Nodejs and express server close the connection after 2 minutes

Im using Express 4.X and node js 0.12.

One of my routes is downloading and processing files, and for some files, downloading and the process takes more than 2 minutes by default. I tried to set the value for more than 2 minutes, but it just does not work, the server closes the connection exactly after 2 minutes each time.

server.timeout = 60 * 60 * 1000; // still closes after 2 minutes server.on('connection', function(socket) { socket.setTimeout(700 * 1000); // still closes after 2 minutes }); res.setTimeout(0);// still closes after 2 minutes req.setTimeout(0);// still closes after 2 minutes res.connection.setTimeout(0);// still closes after 2 minutes 

Also, middleware for connection-timeout is not supported, it just closes the connection after exactly 2 minutes. Tried to change the node version to an older version, but without success. I tried all the options found on the Internet, but the connection still closes ...

+5
source share
3 answers

After several hours of trying each answer, I checked the check with the violinist for this request. It turns out that in my development environment, I use browser synchronization to automatically update the browser window with any changes. In the violinist, I noticed that for a long time with the loading of the POST request, the browser-sync tied it to a socket connection with a 2-minute timeout.

after disabling the browser proxy, the very first solution works like a charm.

 server.on('connection', function(socket) { socket.setTimeout(600 * 60 * 1000); // now works perfectly... }) 
-1
source

server.setTimeout () is a method that sets the HTTP connection timeout for all connections.

The default is 2 minutes.

UPDATED RESPONSE

Try the following:

 var express = require('express'); var http = require('http'); var app = module.exports.app = express(); var server = http.createServer(app); server.setTimeout(10*60*1000); // 10 * 60 seconds * 1000 msecs server.listen(appConfig.port, function () { var logger = app.get('logger'); logger.info('**** STARTING SERVER ****'); }); 

Or that:

 http.request(url).setTimeout() 

It could also be a browser issue. Read this one .

+5
source

What about:

 server.on('connection', function(socket) { socket.setTimeout(5 * 60 * 1000); socket.once('timeout', function() { process.nextTick(socket.destroy); }); }); 
+1
source

Source: https://habr.com/ru/post/1232684/


All Articles