Skip to content

Watch graceful shutdown - #923

Open
bcomnes wants to merge 6 commits into
fastify:mainfrom
bcomnes:fix/watch-graceful-shutdown
Open

bcomnes wants to merge 6 commits into
fastify:mainfrom
bcomnes:fix/watch-graceful-shutdown

Conversation

@bcomnes

@bcomnes bcomnes commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

I noticed that watch mode wasn't waiting for the child process' graceful shutdown when I sent it Ctl-c which was leading me to be confused about weather or not I had a resource leak when killing my dev process. This PR Handles SIGINT and SIGTERM in the watch supervisor so it waits for application child shutdown before exiting. Previously, interrupting watch mode could return the shell prompt while the application was still running asynchronous onClose hooks

Checklist

@bcomnes
bcomnes force-pushed the fix/watch-graceful-shutdown branch from a15e914 to 33cb6ac Compare November 7, 2026 21:42
@bcomnes

bcomnes commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Rebased! Been running locally with success.

@SameRainbows

Copy link
Copy Markdown

Tested locally on Node 24 (Windows). All 6 new graceful shutdown unit tests in test/watch-unit.test.js pass cleanly and npm run lint passes with 0 warnings.

A few points verified in the diff:

  1. Tracking liveChildren in a Set ensures children undergoing restart transitions are still sent GRACEFUL_SHUT and drained rather than orphaned when SIGINT or SIGTERM arrives.
  2. Passing closeGraceDelay into lib/watch/fork.js unifies the timeout between the supervisor and child instead of hardcoding 5000ms.
  3. Setting allStop = true and checking stopping guards against re-entrant shutdown from repeated signals or late file system watch events.
  4. Exiting with 130 on SIGINT and 143 on SIGTERM matches standard process convention.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants