Express 4.x 2分钟后关闭连接

编程入门 行业动态 更新时间:2024-10-22 19:46:33
本文介绍了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分钟: 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分钟后关闭连接

本文发布于:2023-11-27 04:20:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636567.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分钟后   Express

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!