我正在使用Socket运行一个Express.js应用程序。IO的聊天网络应用程序 我在24小时内随机得到了5次以下错误。 节点进程永远被包装起来,并立即重新启动自己。

问题是重新启动Express会把我的用户赶出他们的房间 没有人希望这样。

web服务器通过HAProxy代理。插座不存在稳定性问题, 只是使用websockets和flashsockets传输。 我不能故意复制这个。

这是节点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客户端错误处理程序和未捕获的异常处理程序。 这个似乎捕获了错误:

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

所以我怀疑这不是插座。发送HTTP请求到另一个服务器 或者MySQL/Redis连接。问题在于错误堆栈 不能帮我找出我的代码问题。以下是日志输出:

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

我怎么知道是什么引起的呢?我如何从错误中得到更多?

好吧,不是很啰嗦,但这里是与朗约翰的堆栈跟踪:

    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] ] } }

这里我提供了flash套接字策略文件:

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

这是原因吗?


当前回答

我通过以下方法解决了这个问题:

关闭我的wifi/以太网连接并打开。 我在终端输入:npm update来更新npm。 我试图退出会话并重新登录

之后,我尝试了相同的npm命令,好的事情是它成功了。我不确定是不是那么简单。

我用的是CENTOS 7

其他回答

我通过以下方法解决了这个问题:

关闭我的wifi/以太网连接并打开。 我在终端输入:npm update来更新npm。 我试图退出会话并重新登录

之后,我尝试了相同的npm命令,好的事情是它成功了。我不确定是不是那么简单。

我用的是CENTOS 7

Node JS套接字不阻塞io。考虑使用来自其他源的非阻塞io连接。例如,如果使用带有node的阻塞Java套接字,它只会工作几秒钟,之后就会出现错误。通过实现一个非阻塞的连接来缓解这个问题,例如带有选择器的socketchannel。

First I run my app I got ECONNRESET after that I got error like ECONNREFUSED . I had faced both of this problem while running my node app.For both of the Problem, I found that this was occuring because of not starting the wampserver.I am using mysql database in my app for getting the data with the help of wampserver. I resolve this by starting the wampserver and then after running my node app. It works fine.You can use node or nodemon for running the node application It's not the problem in my case.

我也得到ECONNRESET错误在我的开发过程中,我解决它的方法是不使用nodemon启动我的服务器,只是使用“node server.js”启动我的服务器修复了我的问题。

这很奇怪,但它为我工作,现在我再也没有看到ECONNRESET错误了。

我遇到过类似的问题,在升级Node后,应用程序开始出错。我相信这可以追溯到Node v0.9.10版本的这一项:

net:不压制ECONNRESET (Ben Noordhuis)

以前的版本不会在客户端中断时出错。来自客户端的连接中断会在Node中抛出错误ECONNRESET。我相信这是Node的预期功能,因此修复(至少对我来说)是处理错误,我相信您在unCaught异常中做到了这一点。虽然我在网上处理。套接字处理程序。

你可以这样演示:

创建一个简单的套接字服务器,并获得Node v0.9.9和v0.9.10。

require('net')
    .createServer( function(socket) 
    {
           // no nothing
    })
    .listen(21, function()
     {
           console.log('Socket ON')
    })

使用v0.9.9启动它,然后尝试通过FTP传输到此服务器。我使用FTP和端口21只是因为我在Windows上,有一个FTP客户端,但没有telnet客户端方便。

然后从客户端断开连接。(我正在按Ctrl-C)

在使用Node v0.9.9时应该看到NO ERROR,在使用Node v.0.9.10及更高版本时应该看到ERROR。

在生产环境中,我使用v.0.10。它仍然会给出错误。同样,我认为这是有意的,解决方案是处理代码中的错误。