Express 4.x 2分钟后关闭连接 [英] Express 4.x closes connections after 2 minutes

查看:158
本文介绍了Express 4.x 2分钟后关闭连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个处理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分钟: http://contourline.wordpress.com/2011/03/30/preventing-server-timeout-in-node-js/

I read that http module has a default timeout of 2 minutes: http://contourline.wordpress.com/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分钟后关闭连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆