Node.js 服务每天都会卡死一次

发布于 2024-12-06 21:15:40 字数 742 浏览 2 评论 0原文

这周的每一天我都以重新启动节点服务来开始我的工作日。 每次它只是退出并显示以下消息:

node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: ETIMEDOUT, Connection timed out
at Socket._readImpl (net.js:163:14)
at Socket._onReadable (net.js:633:22)
at IOWatcher.onReadable [as callback] (net.js:177:10)

我无法准确辨别代码的哪一部分导致了该错误,以及为什么该错误如此严重以至于导致节点退出。

无论如何,我已经进行了一些搜索,并认为这可能只是一个未捕获的错误事件。 我已经向每个服务器实例添加了一些 on('error') 侦听器,并带有一些自定义日志消息,以确保捕获它,但无济于事,我今天仍然需要处理常规错误消息。 (真的有必须捕获的“错误”事件之类的事情吗?)

简单的连接超时不应该真正导致整个服务崩溃。

该服务的主要目的是保持与多个连接客户端的开放 TCP 连接,并能够推出 命令(它很像嵌入式产品的私有僵尸网络)。因此,实际上 95% 的时间我们只是闲置 TCP 套接字并发送保持活动的数据包。 所以要求客户端可以随时断开连接而不中断 为其他连接的客户端提供的服务。

我们使用最新的稳定分支节点 v0.4.13-pre 并在 ubuntu 服务器上运行。

Everyday this week I've been beginning my workday with restarting our node service.
And everytime it has simply exited with the following message:

node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: ETIMEDOUT, Connection timed out
at Socket._readImpl (net.js:163:14)
at Socket._onReadable (net.js:633:22)
at IOWatcher.onReadable [as callback] (net.js:177:10)

I'm having trouble discerning exactly wich part of my code is responsible for that error, and exactly why that error is so severe that it makes node exit.

Anyways I've done some searching around and figured that this might just be an uncaught error event.
I've added a few on('error') listeners to every server instance with a bit of customized log message to make sure it's caught, but to no avail, I still got to work today with the regular error message..
(And is there really such a thing as as 'error' events that must be caught?)

A simple connection timeout shouldn't really crash the whole service.

The service's main purpose is to keep an open tcp connection to a number of connecting clients and to be able to push out
commands (It's much like a private botnet for an embedded product). So in effect 95% of the time we're just idling our tcp sockets and sending out keep-alive packets.
So it's a requirement that clients can loose connection at any moment without interrupting
the service for other connected clients.

We're using latest stable branch node v0.4.13-pre and running on an ubuntu server.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑叹一世浮沉 2024-12-13 21:15:40

您是否有与该对象的“错误”事件关联的回调函数?

http://nodejs.org/docs/v0.4.12/api/net .html#event_error_

对于您的所有对象,请确保您对它们各自的“错误”事件有适当的回调,以便它们可以正常退出而不是使您的程序崩溃。

Do you have a callback function associated with the "Error" event for that object?

http://nodejs.org/docs/v0.4.12/api/net.html#event_error_

For all your objects, make sure you have a proper callback for their respective "error" events so they can exit gracefully instead of crashing your program.

柏拉图鍀咏恒 2024-12-13 21:15:40

将类似这样的内容添加到您的代码中:

process.on('uncaughtException', function (err) {
  console.log('Caught Uncaught exception: ' + err);
});

Add something like this to your code:

process.on('uncaughtException', function (err) {
  console.log('Caught Uncaught exception: ' + err);
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文