经过数周的迭代,nodejs setTimout循环停止了 [英] nodejs setTimout loop stopped after many weeks of iterations

查看:56
本文介绍了经过数周的迭代,nodejs setTimout循环停止了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已解决:这是一个节点错误.发生在〜25天(2 ^ 32毫秒)后,请参阅答案以获取详细信息.

Solved : It's a node bug. Happens after ~25 days (2^32 milliseconds), See answer for details.

此循环中是否有最大迭代次数?

Is there a maximum number of iterations of this cycle?

function do_every_x_seconds() {
    //Do some basic things to get x
    setTimeout( do_every_x_seconds, 1000 * x );                                                                
};  

据我了解,这被认为是使事物定期运行的最佳实践"方式,因此,我对此非常怀疑.

As I understand, this is considered a "best practice" way of getting things to run periodically, so I very much doubt it.

我正在Ubuntu上运行具有大量超时循环的Express服务器. 一个每秒运行一次的循环,基本上打印出时间戳. 每5秒调用一次外部http请求的请求 并且每30到300秒运行一次.

I'm running an express server on Ubuntu with a number of timeout loops . One loop that runs every second and basically prints the timestamp. One that calls an external http request every 5 seconds and one that runs every X 30 to 300 seconds.

看起来一切正常.但是,在25天没有任何使用且经过数百万次迭代之后,该节点实例仍处于运行状态,但是所有三个setTimout循环均已停止.根本没有错误消息的报告.

It all seemes to work well enough. However after 25 days without any usage, and several million iterations later, the node instance is still up, but all three of the setTimout loops have stopped. No error messages are reported at all.

甚至更奇怪的是Express服务器仍在运行,我可以将http网站加载到与打印定期时间戳记的控制台相同的控制台上.

Even stranger is that the Express server is still up, and I can load http sites which prints to the same console as where the periodic timestamp was being printed.

我不确定它是否相关,但是我也使用--expose-gc标志运行nodejs并执行定期垃圾回收并监视内存是否在可接受的范围内.

I'm not sure if its related, but I also run nodejs with the --expose-gc flag and perform periodic garbage collection and to monitor that memory is in acceptable ranges.

这是一台开发服务器,因此我保留了该实例,以防万一我可以采取什么措施进一步解决该问题.

It is a development server, so I have left the instance up in case there is some advice on what I can do to look further into the issue.

事件循环可能会以某种方式丢弃所有计时器吗?

Could it be that somehow the event-loop dropped all it's timers?

推荐答案

我有

I have a similar problem with setInterval().

我认为这可能是由Node.js中的以下错误引起的,该错误最近已得到修复:

I think it may be caused by the following bug in Node.js, which seem to have been fixed recently: setInterval callback function unexpected halt #22149

更新:此修补程序似乎已发布在

Update: it seems the fix has been released in Node.js 10.9.0.

这篇关于经过数周的迭代,nodejs setTimout循环停止了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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