如何在 Node.js 中调试错误 ECONNRESET? [英] How do I debug error ECONNRESET in Node.js?

查看:59
本文介绍了如何在 Node.js 中调试错误 ECONNRESET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Socket.io 运行 Express.js 应用程序作为聊天 web 应用程序我在 24 小时内随机收到以下错误约 5 次.节点进程被永久包裹,并立即重新启动.

I'm running an Express.js application using Socket.io for a chat webapp and I get the following error randomly around 5 times during 24h. The node process is wrapped in forever and it restarts itself immediately.

问题是重新启动 Express 会将我的用户踢出他们的房间没有人想要那样.

The problem is that restarting Express kicks my users out of their rooms and nobody wants that.

Web 服务器由 HAProxy 代理.没有套接字稳定性问题,只使用 websockets 和 flashsockets 传输.我不能故意复制这个.

The web server is proxied by HAProxy. There are no socket stability issues, just using websockets and flashsockets transports. I cannot reproduce this on purpose.

这是 Node v0.10.11 的错误:

This is the error with Node v0.10.11:

    events.js:72
            throw er; // Unhandled 'error' event
                  ^
    Error: read ECONNRESET     //alternatively it s a 'write'
        at errnoException (net.js:900:11)
        at TCP.onread (net.js:555:19)
    error: Forever detected script exited with code: 8
    error: Forever restarting script for 2 time

编辑 (2013-07-22)

添加了 socket.io 客户端错误处理程序和未捕获的异常处理程序.似乎这个抓住了错误:

Added both socket.io client error handler and the uncaught exception handler. Seems that this one catches the error:

    process.on('uncaughtException', function (err) {
      console.error(err.stack);
      console.log("Node NOT Exiting...");
    });

所以我怀疑这不是 Socket.io 问题,而是对另一台服务器的 HTTP 请求我做的或 MySQL/Redis 连接.问题是错误堆栈不能帮助我确定我的代码问题.这是日志输出:

So I suspect it's not a Socket.io issue but an HTTP request to another server that I do or a MySQL/Redis connection. The problem is that the error stack doesn't help me identify my code issue. Here is the log output:

    Error: read ECONNRESET
        at errnoException (net.js:900:11)
        at TCP.onread (net.js:555:19)

我怎么知道是什么原因造成的?我如何从错误中获得更多收益?

How do I know what causes this? How do I get more out of the error?

好的,不是很详细,但这是 Longjohn 的堆栈跟踪:

Ok, not very verbose but here's the stacktrace with Longjohn:

    Exception caught: Error ECONNRESET
    { [Error: read ECONNRESET]
      code: 'ECONNRESET',
      errno: 'ECONNRESET',
      syscall: 'read',
      __cached_trace__:
       [ { receiver: [Object],
           fun: [Function: errnoException],
           pos: 22930 },
         { receiver: [Object], fun: [Function: onread], pos: 14545 },
         {},
         { receiver: [Object],
           fun: [Function: fireErrorCallbacks],
           pos: 11672 },
         { receiver: [Object], fun: [Function], pos: 12329 },
         { receiver: [Object], fun: [Function: onread], pos: 14536 } ],
      __previous__:
       { [Error]
         id: 1061835,
         location: 'fireErrorCallbacks (net.js:439)',
         __location__: 'process.nextTick',
         __previous__: null,
         __trace_count__: 1,
         __cached_trace__: [ [Object], [Object], [Object] ] } }

这里我提供闪存套接字策略文件:

Here I serve the flash socket policy file:

    net = require("net")
    net.createServer( (socket) =>
      socket.write("<?xml version="1.0"?>
")
      socket.write("<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
")
      socket.write("<cross-domain-policy>
")
      socket.write("<allow-access-from domain="*" to-ports="*"/>
")
      socket.write("</cross-domain-policy>
")
      socket.end()
    ).listen(843)

这可能是原因吗?

推荐答案

我用于提供闪存策略文件的一个简单的 tcp 服务器导致了这个问题.我现在可以使用处理程序捕获错误:

A simple tcp server I had for serving the flash policy file was causing this. I can now catch the error using a handler:

# serving the flash policy file
net = require("net")

net.createServer((socket) =>
  //just added
  socket.on("error", (err) =>
    console.log("Caught flash policy server socket error: ")
    console.log(err.stack)
  )

  socket.write("<?xml version="1.0"?>
")
  socket.write("<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
")
  socket.write("<cross-domain-policy>
")
  socket.write("<allow-access-from domain="*" to-ports="*"/>
")
  socket.write("</cross-domain-policy>
")
  socket.end()
).listen(843)

这篇关于如何在 Node.js 中调试错误 ECONNRESET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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