In my Node.js application, I use setInterval()
to run a specific function every 1 hour. The function is executed properly for about 25 days, then the timer stop
It's a known bug. Your easiest workaround is to use setTimeout instead, and then in your callback function call another setTimeout.
It seems the bug (#22149) has been fixed in Node.js 10.9.0.
It may be also worth noting that this bug seems to be influencing both setInterval()
and setTimeout()
(as reported here), so the workaround with setTimeout()
in the callback function wouldn't work.
After reading the issue in github, I think they will fix it in the next release. If you need to work around before that, you can try recursive timeout instead. Checkout my code:
function doSomething() {
console.log('test');
}
function doSomethingInterval() {
doSomething();
setTimeout(doSomethingInterval, 1000);
}
doSomethingInterval();