节点js ECONNRESET [英] Node js ECONNRESET

查看:1490
本文介绍了节点js ECONNRESET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个带有socket.io的Express js应用程序,用于聊天
webapp,在
24h期间,我会随机收到以下错误约5次错误。节点进程永久包装,它立即重新启动



问题是重新启动express会将我的用户从客厅
和没有人希望。



网络服务器由HAProxy代理。没有套接字稳定性问题,只需使用websockets和flashsockets传输。我不能故意重现这个。



这是节点v0.10.11的错误:

 事件.js:72 
throw er; //未处理的'错误'事件
^
错误:读取ECONNRESET //或者它在'$'写$'
在errnoException(net.js:900:11)
在TCP。 onread(net.js:555:19)
错误:永远检测到的脚本退出与代码:8
错误:永远重新启动脚本2次

编辑(2013-07-22)



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

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

所以我怀疑这不是一个socket.io问题,而是一个http请求,一个mysql / redis连接。问题是错误堆栈不能帮助我识别我的代码问题。以下是日志输出:

 错误:在errnoException(net.js:900:11)读取ECONNRESET 

在TCP.onread(net.js:555:19)

我该怎么知道导致这个如何从错误中获得更多的收益?好的,不是很详细,但这里的stacktrace与longjohn:

 异常捕获:错误ECONNRESET 
{[错误:读ECONNRESET]
代码:'ECONNRESET',
errno:'ECONNRESET',
syscall:'read'
__cached_trace__:
[{receiver:[Object],
fun:[功能:errnoException],
pos:22930},
{receiver:[Object]乐趣:[功能:onread],pos:14545},
{},
{receiver:[Object],
fun:[功能:fireErrorCallbacks],
pos:11672 },
{receiver:[Object],fun:[Function],pos:12329},
{receiver:[Object],fun:[Function:onread],pos:14536}],
__previous__:
{[错误]
id:1061835,
位置:'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\?> \\\

socket.write(<!DOCTYPE跨域策略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服务器是为了提供Flash策略文件而导致的。我现在可以使用处理程序来捕获错误:

 #为闪存策略文件提供
net = require(net )

net.createServer((socket)=>
//刚添加
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跨域策略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-政策> \\\

socket.end()
).listen(843)


I m running an Express js application with 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.

Problem is that restarting express kicks my users out of their rooms and nobody wants that.

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.

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

EDIT (2013-07-22)

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...");
});

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. 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?

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\"?>\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)

Can this be the cause?

解决方案

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\"?>\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)

这篇关于节点js ECONNRESET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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