How to workaround a nodejs stable bug with setInterval/setTimeout when changing system time

泪湿孤枕 提交于 2019-12-24 03:18:25

问题


In the current stable version of node.js v0.10.33 there is a bug where setTimeout/setInterval does not fire anymore when setting the system time to the past.

Run this code to see what I mean:

var i = 0;

var handle = setInterval(function()
{
    console.log(++i);
}, 1000);

Then while it's running change the time of your system to the past, does not matter if on windows or linux. The interval / timeout will not fire anymore. When chaning the time to the future, node behaves perfectly fine and keeps running the interval. This bug was fixed in node v0.11.3 which I cannot use yet because it is not stable.

I tried modules like timer-shim and nanotimer but they internally use setInterval/setTimeout aswell and thus have the same problem.

For the time being, how can I woraround this node bug for my application in the best possible way without funky monkey patching?


回答1:


This is fixed in older versions of the 0.10 branch: https://nodejs.org/en/blog/release/v0.10.36/



来源:https://stackoverflow.com/questions/27458602/how-to-workaround-a-nodejs-stable-bug-with-setinterval-settimeout-when-changing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!