Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

335
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!