Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

343
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda