feat: adapter-node shutdown event #12153
Open
+30
−19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a small improvement and the missing piece to the recent graceful shutdown feature.
After the server has closed gracefully Node will emit the
exit
event. As others have pointed out however if you have something running in the background the app will continue to run andexit
will never be emitted. Theexit
event isn't ideal anyway because it will close your app as soon as possible so we can't do any custom async cleanup work in aprocess.on('exit', () => { ... })
handler. That means callingprocess.exit()
to manually emit theexit
event isn't an option. It defeats the point of a graceful shutdown. This PR emits a custom event instead that users ofadapter-node
can listen to and use to perform any kind of cleanup work right after the HTTP server has closed.We briefly discussed the option of exporting a function to register a hook instead but with the way adapters work this doesn't seem to be possible today.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.Edits