【问题标题】:Express 4.x closes connections after 2 minutesExpress 4.x 在 2 分钟后关闭连接
【发布时间】:2014-11-13 13:22:17
【问题描述】:

我有一个处理GET /foo 的简单节点应用程序。这个请求需要一些时间来计算和返回一个文件。 每次请求持续超过 2 分钟,连接就会关闭。我正在使用 Express 4.10.2 和节点 0.10.32。

我读到 http 模块的默认超时时间为 2 分钟: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
});

但是即使两分钟后连接没有关闭,当服务器尝试将文件发回时,我得到:

{ [Error: Request aborted] code: 'ECONNABORT' }

编辑:

server.setTimeout(5*60*1000); 工作正常!谢谢@mscdex

【问题讨论】:

  • 您是否在connection 事件处理程序之外尝试了server.setTimeout(5*60*1000)
  • 我会试试的。让你知道在几。谢谢

标签: node.js express


【解决方案1】:

server.setTimeout() 是为所有连接设置 HTTP 连接超时的方法。

【讨论】:

    猜你喜欢
    • 2015-12-29
    • 1970-01-01
    • 2018-05-10
    • 1970-01-01
    • 2021-06-29
    • 2022-10-07
    • 1970-01-01
    • 1970-01-01
    • 2016-05-22
    相关资源
    最近更新 更多