Node-restify: ECONNRESET after 2 minutes

Created on 12 May 2015  路  4Comments  路  Source: restify/node-restify

I have a route setup for receiving a file stream and processing a large amount of CSV data. (~18MB & ~78k lines).

The processing takes about 5 minutes total, but clients are disconnected at the 2 minute mark. The route continues to process the file and completes with no errors on the server side at about 5 minutes after the request is initiated.

When testing with the request module as the client, it returns: { [Error: socket hang up] code: 'ECONNRESET' }

When testing with Curl via the command line, it returns: curl: (52) Empty reply from server. Using the --connect-timeout flag did not make a difference.

I'm unsure if this is a restify issue or not, but I am pretty certain it's not a client or the code doing the processing.

When I test with smaller CSV files that process in under 2 minutes, the client receives the response just fine.

Just for a general reference, my route looks something like this:

server.post(config.apiBase + '/items/upload', function(req, res, next) {
    let stream = fs.createReadStream(req.files.file.path);
    let csvStream = csv({headers: true})
      .validate(function(data) {}
      .on('data', function(data) { // processing data here }
      .on('error', function(data) { // this never is hit }
      .on('end', function(data) { return res.send(results); // hits minutes after connection is closed }
    });
    stream.pipe(csvStream);
    ...

Most helpful comment

I figured out the default timeout on the http server is 2 minutes. It can be overridden with server.setTimeout() .. although server in this case is the http server and not the restify object.

https://nodejs.org/api/http.html#http_class_http_server

The solution is to call setTimeout on the the server property of the restify server: (i.e. server.server.setTimeout(milliseconds))

var server = restify.createServer(myconfig);

// Set timeout in milliseconds. This would be 5 minutes.
server.server.setTimeout(60000*5);

All 4 comments

I figured out the default timeout on the http server is 2 minutes. It can be overridden with server.setTimeout() .. although server in this case is the http server and not the restify object.

https://nodejs.org/api/http.html#http_class_http_server

The solution is to call setTimeout on the the server property of the restify server: (i.e. server.server.setTimeout(milliseconds))

var server = restify.createServer(myconfig);

// Set timeout in milliseconds. This would be 5 minutes.
server.server.setTimeout(60000*5);

Obrigado @mikemilano, me ajudou muito sua resposta.

@mikemilano
Is it possible to set the timeout for special requests?
e.g. /download/*

server.server.setTimeout(320 * 1000);

Was this page helpful?
0 / 5 - 0 ratings