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

211
Views
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
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!