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

342
Views
Asynchronous tasks when node server.close() invoked

I'm working on an node+express application and want to prepare it to make a graceful. The goal is to make deployments in the "right" way, that is:

  • Avoid accepting requests
  • Finish the current ones
  • Terminate node process
  • Put new code
  • Restart server-

For the graceful shutdown I'm using a code similar to:

var express = require('express');
var app = express();
var server = app.listen(1337);

process.on( 'SIGTERM', function () {

   server.close(function () {
     console.log( "Closed out remaining connections.");
     // Close db connections, etc.
     //
     // How to ensure no tasks is running in the thread pool ???
   });

   setTimeout( function () {
     console.error("Could not close connections in time, forcefully shutting down");
     process.exit(1); 
   }, 30*1000);

});

My doubt is to know if inside server.close() can I be sure no task is running or pending execution ?

What happens if a job in the event loop started reading a big file asynchronously and is working in the thread pool? Does server.close warranties no tasks are running in the thread pool too?

over 4 years ago · Santiago Trujillo
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!