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

331
Visualizações
What is the default behaviour of Node.js on receiving SIGTERM?

I've been reading documentation and it's not explicitly stated whether the Node.js process immediately exits or not if no signal handler is registered. For example, are pending tasks in the poll queue executed or is everything dropped? Does the programmer always have to handle graceful shutdown explicitly by keeping track of all pending promises?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

When no handler is added for SIGTERM, node will reset the terminal and exit the process immediately. It's a "drop everything where it is" exit. Even more so than so than process.exit which does still allow the exit event to fire:

Calling process.exit() will force the process to exit as quickly as possible even if there are still asynchronous operations pending that have not yet completed fully, including I/O operations to process.stdout and process.stderr.

When a signal handler is added (process.once('SIGTERM'), the handler code is scheduled for the next event loop. So behaviour immediately changes even if you just call process.exit() in the handler.

Promises, or Javascript generally for that matter, don't have the concept of cancellation built in yet. You could track promises but unless the underlying API's being used specifically address ways to cancel tasks then there's not much to do.

You can just wait though. In the average web application if you close the web server and close the database connection. Existing connections will complete, no new connections will initiate, eventually the process will exit by itself when there is nothing left on the event loop to run. wtfnode can be handy to help debug processes that aren't eventually exiting like this.

over 4 years ago · Santiago Trujillo Relatório
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