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

215
Vistas
NodeJS - Close Pg DB Pool on Process Exit

I've written the following code to ensure my pg-db pool is closed in the event of the process exiting.

['exit', 'SIGINT', 'SIGUSR1', 'SIGUSR2', 'uncaughtException', 'SIGTERM'].forEach(ev => { 
     process.on(ev, cleanUp.bind(null, ev));
});

where cleanUp is defined as follows:

let didEnd = false

function cleanUp(options, exCode) { 
  try {
   if (!didEnd) { 
     didEnd = true
     console.log('closing pool')
     pool.end(() => {}))
   }
  } catch(ex) { 
   process.exit(1)
}

I've noticed that when this code executes, the closing pool string is logged and the process seems to hang and not terminate gracefully when this code executes. Shouldn't the exit signal continue to execute once the cleanUp method runs, terminating the process?

about 4 years ago · Juan Pablo Isaza
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