我有一个处理GET /foo的简单节点应用程序.该请求需要一些时间来计算并返回文件. 每次请求持续2分钟以上时,连接都会关闭.我正在使用Express 4.10.2和节点0.10.32.
I have a simple node application which handles GET /foo. This request takes some time to compute and return a file. Each time the request lasts more than 2 minutes, the connection is closed. I'm using Express 4.10.2 and node 0.10.32.
我了解到http模块的默认超时为2分钟: contourline.wordpress/2011/03/30/preventing-server-timeout-in-node-js/
I read that http module has a default timeout of 2 minutes: contourline.wordpress/2011/03/30/preventing-server-timeout-in-node-js/
我尝试使用:
server.on('connection', function(socket) { socket.setTimeout(5*60*1000); //5 minutes });但是即使两分钟后连接仍未关闭,当服务器尝试将文件发送回时,我得到了:
But even if the connection is not closed after two minutes, when the server tried to send the file back, I got:
{ [Error: Request aborted] code: 'ECONNABORT' }
server.setTimeout(5*60*1000);正常工作!谢谢@mscdex
server.setTimeout(5*60*1000); works fine! Thanks @mscdex
推荐答案是为所有连接设置HTTP连接超时的方法.
server.setTimeout() is the method that sets the HTTP connection timeout for all connections.
更多推荐
Express 4.x 2分钟后关闭连接
发布评论