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?