Skip to content

setInterval stops working after the service has been running for some time (so far 4-10 days). #41037

Closed as not planned

Description

@ThabetSabha

Version

v12.18.1

Platform

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!

Activity

  1. added
    timersIssues and PRs related to timers, setImmediate(), setInterval(), and setTimeout().
    on Nov 30, 2021
  2. Trott commented on Dec 3, 2021

    @Trott
    Member

    @nodejs/timers

  3. kerus1024 commented on Dec 23, 2021

    @kerus1024

    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.

  4. benjamingr commented on Dec 24, 2021

    @benjamingr
    Member

    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.

  5. apapirovski commented on Jan 6, 2022

    @apapirovski
    Contributor

    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.

  6. Fishrock123 commented on Jan 6, 2022

    @Fishrock123
    Contributor

    @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

  7. ThabetSabha commented on Jan 9, 2022

    @ThabetSabha
    Author

    @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!

  8. bnoordhuis commented on Feb 25, 2022

    @bnoordhuis
    Member

    @kerus1024 what operating system and architecture (uname -a) were (are?) you running at the time?

  9. kerus1024 commented on Feb 25, 2022

    @kerus1024

    @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;

  10. bnoordhuis commented on Feb 25, 2022

    @bnoordhuis
    Member

    My hunch was an aarch64 kernel bug (libuv already works around several) but no such issues exist on x86_64, to my knowledge.

  11. bnoordhuis commented on Dec 29, 2022

    @bnoordhuis
    Member

    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.

  12. zzmichalqq commented on Apr 14, 2023

    @zzmichalqq

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    timersIssues and PRs related to timers, setImmediate(), setInterval(), and setTimeout().

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions