You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
setInterval stops working after the service has been running for some time (so far 4-10 days). #41037
Linux DEV-PH-CVR-02 4.9.140-tegra #1 SMP PREEMPT Sat Oct 19 15:54:06 PDT 2019 aarch64 aarch64 aarch64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
I am running this function inside of a service, the socket here is a tls-socket, after this service keeps running for an arbitrary number of days, the callback provided to setInterval stops getting executed, I am quite confident this is an issue with setInterval as the rest of the process keeps functioning as expected, I tried looking for some possible resource leakage, unhandled errors, etc.. in the service, but couldn't find any.
startPing() {
console.log(`will start sending pings in 60 seconds`)
this.pingInterval = setInterval(() => {
console.log("sending ping", new Date())
this.socket.write('ping');
// if no response is recieved after whenToTimeut number of seconds, invoke timeout to try to reconnect.
const whenToTimeOut = 30* 1000
this.socket.setTimeout(whenToTimeOut);
}, 60*1000)
}
How often does it reproduce? Is there a required condition?
seems to happen every time the process has been running for a while, but didn't have the opportunity to figure out how long after it's been running exactly does this happen.
What is the expected behavior?
setInterval keeps running as normal.
What do you see instead?
setInterval stops executing its callback.
Additional information
I am not 100% sure this is an issue with setInterval, but I couldn't find any other possible reason for the bug, and saw some people mentioning the same issue here: #22149 (have to scroll down).
If this is already solved, it would be great if a way to replicate this issue could be provided, thanks!
It stops when it's almost two months using timeout and promise.
The shorter the interval, the faster it stops, and more faster it stops with axios request.
It has occurred since 2017, when I worked on it, and it has not been resolved regardless of the version. (I first used nodejs in 2017)
There is no error.
I'm handling unhandledexception, but the event doesn't appear.
For what it's worth I tried running a code similar to the OP for a few days (though with a different OS) and was unable to reproduce. If there is a repo I can clone and run for a few days to reproduce with all the debug logs active and strace that would be useful.
It has occurred since 2017, when I worked on it, and it has not been resolved regardless of the version. (I first used nodejs in 2017)
The timers code, other than usage of libuv, has been almost entirely rewritten since 2017 so if this is indeed the case, it seems like either C++ or libuv layer bug. I'll try to investigate but the fact that we haven't been able to get a barebones, reliable reproduction from anyone, makes this really hard.
The problem is that this is a private company repo so I can't share the code, as for the duration, like I said it's arbitrary, on some servers it happens after a few days, others after a few weeks, and others don't have the issue at all.
I absolutely understand how hard this would be to debug, I just wanted to point it out, and maybe understand what is causing it, as for the time being, I already re-wrote the code using node-cron, and I haven't ran into the issue yet, but will need to see how it performs long term.
it is running on 4.19.0-18-amd64 (general cloud providers linux vm instance)
when it throws an error, it is not work for next loop in await loop around once in 40 days.
I'm not sure but i think it is an axios problem.
I have been working to log whether it is a problem of axios or settimeout waitloop.
sorry for confusion;
This issue has been open for a while with no movement, node v12.x has been out of support for some time, and it's not even clear whether it's a bug in node or some other component, so I'm going to close it.
Activity
Trott commentedon Dec 3, 2021
@nodejs/timers
kerus1024 commentedon Dec 23, 2021
I'm experiencing the same problem.
It stops when it's almost two months using timeout and promise.
The shorter the interval, the faster it stops, and more faster it stops with axios request.
It has occurred since 2017, when I worked on it, and it has not been resolved regardless of the version. (I first used nodejs in 2017)
There is no error.
I'm handling unhandledexception, but the event doesn't appear.
current node version is 16.13.0.
benjamingr commentedon Dec 24, 2021
For what it's worth I tried running a code similar to the OP for a few days (though with a different OS) and was unable to reproduce. If there is a repo I can clone and run for a few days to reproduce with all the debug logs active and strace that would be useful.
apapirovski commentedon Jan 6, 2022
The timers code, other than usage of libuv, has been almost entirely rewritten since 2017 so if this is indeed the case, it seems like either C++ or libuv layer bug. I'll try to investigate but the fact that we haven't been able to get a barebones, reliable reproduction from anyone, makes this really hard.
Fishrock123 commentedon Jan 6, 2022
@bnoordhuis would probably be the best person to know if it was a libuv bug: https://github.com/libuv/libuv/commits/v1.x/src/timer.c
ThabetSabha commentedon Jan 9, 2022
@benjamingr, @apapirovski
The problem is that this is a private company repo so I can't share the code, as for the duration, like I said it's arbitrary, on some servers it happens after a few days, others after a few weeks, and others don't have the issue at all.
I absolutely understand how hard this would be to debug, I just wanted to point it out, and maybe understand what is causing it, as for the time being, I already re-wrote the code using node-cron, and I haven't ran into the issue yet, but will need to see how it performs long term.
either way, thanks everyone for the help!
bnoordhuis commentedon Feb 25, 2022
@kerus1024 what operating system and architecture (
uname -a) were (are?) you running at the time?kerus1024 commentedon Feb 25, 2022
@bnoordhuis
it is running on 4.19.0-18-amd64 (general cloud providers linux vm instance)
when it throws an error, it is not work for next loop in await loop around once in 40 days.
I'm not sure but i think it is an axios problem.
I have been working to log whether it is a problem of axios or settimeout waitloop.
sorry for confusion;
bnoordhuis commentedon Feb 25, 2022
My hunch was an aarch64 kernel bug (libuv already works around several) but no such issues exist on x86_64, to my knowledge.
bnoordhuis commentedon Dec 29, 2022
This issue has been open for a while with no movement, node v12.x has been out of support for some time, and it's not even clear whether it's a bug in node or some other component, so I'm going to close it.
zzmichalqq commentedon Apr 14, 2023
Same issue happening to me on Node v19.2.0. Will try to use a stable v18.16.0 and see if the issue persists. I described the issue more here: Node.js - setTimeout is sometimes not being fired