Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handle Request Aborted in Node js using Connect Multiparty

Error: Request aborted
at IncomingMessage.onReqAborted (D:\ProjectName\node_modules\express\node_modules\connect\node_modules\multiparty\index.js:131:17)
at IncomingMessage.EventEmitter.emit (events.js:92:17)
at abortIncoming (http.js:1911:11)
at Socket.serverSocketCloseListener (http.js:1923:5)
at Socket.EventEmitter.emit (events.js:117:20)
at TCP.close (net.js:466:12)

I am getting this error when uploading multiple file in node js using connect multiparty middleware. I am not even uploading big size files. its not more than 50mb. Specifically getting this error when internet connection is disconnected while uploading files. Is there a any way to handle this error.

like image 782
R J. Avatar asked Jun 20 '14 13:06

R J.


1 Answers

In my case, I can resolve adding more request / response timeout.

If you're using express:

var server = app.listen(app.get('port'), function() {
  debug('Express server listening on port ' + server.address().port);
});
server.timeout = 1000 * 60 * 10; // 10 min

There is also a middleware for Connect / Express: https://github.com/expressjs/timeout

If you're not using express and are only working with vanilla node:

var http = require('http');
var server = http.createServer(function (req, res) {
  setTimeout(function() {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World\n');
  }, 200);
}).listen(3000, '127.0.0.1');

server.timeout = 1000 * 60 * 10; // 10 min
console.log('Server running at http://127.0.0.1:3000/');
like image 78
slorenzo Avatar answered Oct 29 '22 15:10

slorenzo