nodemon: Nodemon doesn't wait for async graceful exit handlers

  • Versions: node@v18.14.0, darwin@22.5.0
  • nodemon -v: 2.0.22
  • Operating system/terminal environment (powershell, gitshell, etc): Terminal.app on macOS, running zsh
  • Using Docker? What image: No
  • Command you ran: npx nodemon hello.js

Expected behaviour

The process should keep running in the foreground until the shutdown handler is finished.

Actual behaviour

The process continues in the foreground until the first await, then “soft exists” (causes the terminal prompt to be displayed), but doesn’t kill the process.

https://github.com/remy/nodemon/assets/43803932/d1cc85cb-e2a7-4d21-a128-655f65d3b81c

Steps to reproduce

Run this file via nodemon, then ctrl+c it to shut it down:

/* file: hello.js */
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

const interval = setInterval(() => console.log('tick'), 1000);

async function shutdown() {
  console.log('shutting down');
  await sleep(1000);
  clearInterval(interval);
  console.log('shutdown complete');
  process.exit(0);
}

process.on('SIGHUP', () => shutdown());
process.on('SIGINT', () => shutdown());
process.on('SIGTERM', () => shutdown());

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 5
  • Comments: 18 (2 by maintainers)

Most upvoted comments

This is definitely not stale, it’s a real pain when running our webserver in dev mode, and it keeps messing with my terminal.

Still an issue, please don’t close!