2分钟后,Nodejs和Express服务器关闭连接 [英] Nodejs and express server closes connection after 2 minutes
问题描述
我使用Express 4.X和节点js 0.12。
Im using Express 4.X and node js 0.12.
我的一条路由是用于文件上传和处理,以及上传和进程所需的某些文件超过2分钟默认超时。我已经设法将timeout设置为超过2分钟的值,但是它不正常,服务器每次在两分钟后完全关闭连接。
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...
推荐答案
经过几个小时的尝试每一个答案都可以提供,我已经用fiddler进行了检查。事实证明,在我的开发环境中,使用浏览器同步可以在任何更改时自动刷新浏览器窗口。在fiddler中,我注意到长时间的上传POST请求浏览器同步将其绑定到一个有2分钟超时的套接字连接。
After a few hours of trying every answer available I had run an inspection with fiddler for that request. Turns out that in my development environment im using browser-sync for auto refreshing the browser window on any change. In fiddler i noticed that a long with the upload POST request browser-sync tied it to a socket connection which had 2 minute timeout.
关闭浏览器同步代理第一个解决方案就像一个魅力一样。
after switched off the browser-sync proxy the very first solution worked like a charm.
server.on('connection', function(socket) {
socket.setTimeout(600 * 60 * 1000); // now works perfectly...
})
这篇关于2分钟后,Nodejs和Express服务器关闭连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!