Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

109
Visualizações
NodeJS v12.18.1 SetInterval stops running after a few days

I am using a setInterval function to send a ping every minute, problem is that after an arbitrary number of days,the setInteval callback no longer gets executed. I am aware of the issue that was fixed in v10.9.0 https://github.com/nodejs/node/issues/22149, but this is is happening in version 12, and not after 25 days.

this is a simplified version of what I am using setInterval for:

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)
}

After reading about the issues with setInterval I've decided to use node-cron for now, I know it uses setTimeout under the hood, but we also have a process running using it, and it doesn't stop even when the ping process stops.

What I am wondering is, has anyone faced this issue before, and has anyone figured out a way to replicate it (couldn't do it using libfaketime), because even if I use the node-cron package, I still wanna make sure that it's the setInterval that was causing the issue.

PS. I've tried to look for any possible resource leakage problem, but couldn't find any, and the process is running fine aside from the ping process stopping.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda