Im using Express 4.X and node js 0.12.
One of my routes is for file uploading and processing and for some of the files the upload and process takes more than the 2 minutes default timeout. I have tried to settimeout to values more than 2 minutes but its just not working, the server closes connection exactly after 2 minutes every 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
The connect-timeout middleware is not helped either, it just keeps closing the connection after exactly 2 minutes. Tried changing the node version to older version but with no success. Tried all the variations found online, but the connection still closes...
Definition and Usage. The server.timeout property sets, or gets, the server's timeout value, in milliseconds. Default is 2 minutes (120000 milliseconds) Set the server. timeout property to 0 to avoid having a default timeout value.
By default, normal HTTP requests to Node. js/Express/Sails. js apps time out after 2 minutes (120000 milliseconds) if a response is not sent.
Simply put, you need to configure the timeout value on the HTTP Server that express generates when you call the listen method. For example: // create an express app const app = express(); // add a route that delays response for 3 minutes app. get('/test', (req, res) => { setTimeout(() => { res.
Since Node. js uses non-blocking IO, the server can handle multiple requests without waiting for each one to complete, which means Node. js can handle a much higher volume of web traffic than other more traditional languages.
server.setTimeout() is the method that sets the HTTP connection timeout for all connections.
The 2 minutes are default.
UPDATED ANSWER
Try this:
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 this:
http.request(url).setTimeout()
Also, it can be a browser issue. Read this.
how about:
server.on('connection', function(socket) {
socket.setTimeout(5 * 60 * 1000);
socket.once('timeout', function() {
process.nextTick(socket.destroy);
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With