title: How do I debug error ECONNRESET in Node.js?
body: <p>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.</p>
  
  <p>The problem is that restarting Express kicks my users out of their rooms 
  and nobody wants that.</p>
  
  <p>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.</p>
  
  <p>This is the error with Node <code>v0.10.11</code>:</p>
  
  <pre><code>    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
  </code></pre>
  
  <p><strong>EDIT (2013-07-22)</strong></p>
  
  <p>Added both socket.io client error handler and the uncaught exception handler.
  Seems that this one catches the error:</p>
  
  <pre><code>    process.on('uncaughtException', function (err) {
        console.error(err.stack);
        console.log("Node NOT Exiting...");
      });
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>    Error: read ECONNRESET
          at errnoException (net.js:900:11)
          at TCP.onread (net.js:555:19)
  </code></pre>
  
  <p>How do I know what causes this? How do I get more out of the error?</p>
  
  <p>Ok, not very verbose but here's the stacktrace with Longjohn:</p>
  
  <pre><code>    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] ] } }
  </code></pre>
  
  <p>Here I serve the flash socket policy file:</p>
  
  <pre><code>    net = require("net")
      net.createServer( (socket) =&gt;
        socket.write("&lt;?xml version=\"1.0\"?&gt;\n")
        socket.write("&lt;!DOCTYPE cross-domain-policy SYSTEM \"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd\"&gt;\n")
        socket.write("&lt;cross-domain-policy&gt;\n")
        socket.write("&lt;allow-access-from domain=\"*\" to-ports=\"*\"/&gt;\n")
        socket.write("&lt;/cross-domain-policy&gt;\n")
        socket.end()
      ).listen(843)
  </code></pre>
  
  <p>Can this be the cause?</p>