“错误:插座挂起”与快递 [英] "Error: socket hang up" with Express
本文介绍了“错误:插座挂起”与快递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当客户端刷新页面时,节点会在我重新启动时(因为套接字被终止,而我仍在处理请求)。错误:
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:
-
req
对象 - 返回值
listen
(我正在使用Express) - 我的
获得
,的返回值使用
和发布
方法。
req
objects- The return value of
listen
(I am using Express) - The return value of my
get
,use
andpost
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屋!
查看全文