How do I debug error ECONNRESET in Node.js?

后端 未结 14 1448
刺人心
刺人心 2020-11-22 04:02

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 for

14条回答
  •  执念已碎
    2020-11-22 04:27

    I had a similar problem where apps started erroring out after an upgrade of Node. I believe this can be traced back to Node release v0.9.10 this item:

    • net: don't suppress ECONNRESET (Ben Noordhuis)

    Previous versions wouldn't error out on interruptions from the client. A break in the connection from the client throws the error ECONNRESET in Node. I believe this is intended functionality for Node, so the fix (at least for me) was to handle the error, which I believe you did in unCaught exceptions. Although I handle it in the net.socket handler.

    You can demonstrate this:

    Make a simple socket server and get Node v0.9.9 and v0.9.10.

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

    Start it up using v0.9.9 and then attempt to FTP to this server. I'm using FTP and port 21 only because I'm on Windows and have an FTP client, but no telnet client handy.

    Then from the client side, just break the connection. (I'm just doing Ctrl-C)

    You should see NO ERROR when using Node v0.9.9, and ERROR when using Node v.0.9.10 and up.

    In production, I use v.0.10. something and it still gives the error. Again, I think this is intended and the solution is to handle the error in your code.

提交回复
热议问题