mscdex / busboy

A streaming parser for HTML form data for node.js
MIT License
2.84k stars 213 forks source link

ERR_CONNECTION_ABORTED with long file uploads #336

Closed llaurenss closed 1 year ago

llaurenss commented 1 year ago

When im uploading a file after 5-11 minutes the upload will fail and say ERR_CONNECTION_ABORTED im not getting any errors in the Nodejs server. It happens no matter the file size or upload speed. If the file finishes uploading before the 5-11 minute mark everything is fine. I've also tried a different browser but with no success.

I've also recorded a video, I've throttled the network speed to 8mbps so the file upload wouldn't be uploaded instantly because its on localhost. https://youtu.be/uR4AtencXJw

This is my code:

const http = require('http');
const fs = require('fs');

const busboy = require('busboy');

http.createServer((req, res) => {
  if (req.method === 'POST') {
    console.log('POST request');
    const bb = busboy({ headers: req.headers });
    bb.on('file', (name, file, info) => {
      file.pipe(fs.createWriteStream("./upload/test"));
    });

    bb.on('close', () => {
      console.log('Done parsing form!');
      res.writeHead(303, { Connection: 'close', Location: '/' });
      res.end();
    });

    req.pipe(bb);
  } else if (req.method === 'GET') {
    res.writeHead(200, { Connection: 'close' });
    res.end(`
      <html>
        <head></head>
        <body>
          <form method="POST" enctype="multipart/form-data">
            <input type="file" name="filefield"><br />
            <input type="text" name="textfield"><br />
            <input type="submit">
          </form>
        </body>
      </html>
    `);
  }
}).listen(8000, () => {
  console.log('Listening for requests');
});
mscdex commented 1 year ago

Which node.js versions have you tried with?

mscdex commented 1 year ago

Also, what version of busboy are you using?

llaurenss commented 1 year ago

busboy is version 1.6.0 and node.js v18.15.0

edit: I updated node.js to v18.16.0 now but same thing happens

llaurenss commented 1 year ago

node.js v19.9.0 also same thing happening

llaurenss commented 1 year ago

Found the problem, the http server has a default timeout of 300 seconds which you can change with server.requestTimeout

mscdex commented 1 year ago

FWIW I've now added a note about this in the readme in d08cc9cc5572a29354480f6ec829a042c68d8bac.