{"id":206,"hash":"ee5c790d874b95a99fcee6336bf0bf85bd99923139dbbd2c9b84cedd44757b96","pattern":"How do I debug error ECONNRESET in Node.js?","full_message":"I'm running an Express.js application using Socket.io for a chat webapp\nand I get the following error randomly around 5 times during 24h.\nThe node process is wrapped in forever and it restarts itself immediately.\n\nThe problem is that restarting Express kicks my users out of their rooms \nand nobody wants that.\n\nThe web server is proxied by HAProxy. There are no socket stability issues, \njust using websockets and flashsockets transports.\nI cannot reproduce this on purpose.\n\nThis is the error with Node v0.10.11:\n\n    events.js:72\n            throw er; // Unhandled 'error' event\n                  ^\n    Error: read ECONNRESET     //alternatively it s a 'write'\n        at errnoException (net.js:900:11)\n        at TCP.onread (net.js:555:19)\n    error: Forever detected script exited with code: 8\n    error: Forever restarting script for 2 time\n\nEDIT (2013-07-22)\n\nAdded both socket.io client error handler and the uncaught exception handler.\nSeems that this one catches the error:\n\n    process.on('uncaughtException', function (err) {\n      console.error(err.stack);\n      console.log(\"Node NOT Exiting...\");\n    });\n\nSo I suspect it's not a Socket.io issue but an HTTP request to another server \nthat I do or a MySQL/Redis connection. The problem is that the error stack \ndoesn't help me identify my code issue. Here is the log output:\n\n    Error: read ECONNRESET\n        at errnoException (net.js:900:11)\n        at TCP.onread (net.js:555:19)\n\nHow do I know what causes this? How do I get more out of the error?\n\nOk, not very verbose but here's the stacktrace with Longjohn:\n\n    Exception caught: Error ECONNRESET\n    { [Error: read ECONNRESET]\n      code: 'ECONNRESET',\n      errno: 'ECONNRESET',\n      syscall: 'read',\n      __cached_trace__:\n       [ { receiver: [Object],\n           fun: [Function: errnoException],\n           pos: 22930 },\n         { receiver: [Object], fun: [Function: onread], pos: 14545 },\n         {},\n         { receiver: [Object],\n           fun: [Function: fireErrorCallbacks],\n           pos: 11672 },\n         { receiver: [Object], fun: [Function], pos: 12329 },\n         { receiver: [Object], fun: [Function: onread], pos: 14536 } ],\n      __previous__:\n       { [Error]\n         id: 1061835,\n         location: 'fireErrorCallbacks (net.js:439)',\n         __location__: 'process.nextTick',\n         __previous__: null,\n         __trace_count__: 1,\n         __cached_trace__: [ [Object], [Object], [Object] ] } }\n\nHere I serve the flash socket policy file:\n\n    net = require(\"net\")\n    net.createServer( (socket) =>\n      socket.write(\"<?xml version=\\\"1.0\\\"?>\\n\")\n      socket.write(\"<!DOCTYPE cross-domain-policy SYSTEM \\\"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd\\\">\\n\")\n      socket.write(\"<cross-domain-policy>\\n\")\n      socket.write(\"<allow-access-from domain=\\\"*\\\" to-ports=\\\"*\\\"/>\\n\")\n      socket.write(\"</cross-domain-policy>\\n\")\n      socket.end()\n    ).listen(843)\n\nCan this be the cause?","ecosystem":"npm","package_name":"node.js","package_version":null,"solution":"A simple tcp server I had for serving the flash policy file was causing this. I can now catch the error using a handler:\n\n# serving the flash policy file\nnet = require(\"net\")\n\nnet.createServer((socket) =>\n  //just added\n  socket.on(\"error\", (err) =>\n    console.log(\"Caught flash policy server socket error: \")\n    console.log(err.stack)\n  )\n\n  socket.write(\"<?xml version=\\\"1.0\\\"?>\\n\")\n  socket.write(\"<!DOCTYPE cross-domain-policy SYSTEM \\\"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd\\\">\\n\")\n  socket.write(\"<cross-domain-policy>\\n\")\n  socket.write(\"<allow-access-from domain=\\\"*\\\" to-ports=\\\"*\\\"/>\\n\")\n  socket.write(\"</cross-domain-policy>\\n\")\n  socket.end()\n).listen(843)","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/17245881/how-do-i-debug-error-econnreset-in-node-js","votes":467,"created_at":"2026-04-19T04:41:32.690942+00:00","updated_at":"2026-04-19T04:51:14.643339+00:00"}