“错误:插座挂起”与快递 [英] "Error: socket hang up" with Express

查看:239
本文介绍了“错误:插座挂起”与快递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当客户端刷新页面时,节点会在我重新启动时(因为套接字被终止,而我仍在处理请求)。错误:

Node keeps quitting on me when a client refreshes while still loading a page (so the socket gets terminated, while I am still processing the request). The error:

[ERROR] - Error: socket hang up
   at createHangUpError (http.js:1472:15)
   at Socket.socketCloseListener (http.js:1522:23)
   at Socket.EventEmitter.emit (events.js:95:17)
   at TCP.close (net.js:465:12) (at lib/Maintenance.js:38)

我尝试附加 on('error',... to:


  1. req 对象

  2. 返回值 listen (我正在使用Express)

  3. 我的获得的返回值使用发布方法。

  1. req objects
  2. The return value of listen (I am using Express)
  3. The return value of my get, use and post methods.

然而,我似乎无法捕捉到这个错误;它仍然被抛出,我的错误处理程序都没有反应。我可能会丢失什么?

And yet, I cannot seem to catch that error; it still gets thrown and none of my error handlers react. What could I possibly be missing?

推荐答案

将错误侦听器附加到套接字对象

Attach error listeners to the socket objects

app.use(function(req, res, next) {
    req.socket.on("error", function() {

    });
    res.socket.on("error", function() {

    });
    next();
});

这篇关于“错误:插座挂起”与快递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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