Repository navigation
fix: let the process exit on SIGINT and SIGTERM after the span cache is used - #2846
Open
Abhishek B R (Abhishek-B-R) wants to merge 1 commit into
Open
Abhishek B R (Abhishek-B-R) wants to merge 1 commit into
Abhishek B R (Abhishek-B-R) wants to merge 1 commit into
Conversation
…is used The span cache registers SIGINT and SIGTERM listeners the first time it creates its temp file. Node drops its default exit behaviour for a signal once anything listens for it, so after the first Eval() a long running process (a server, a watch loop, a container receiving SIGTERM) ignored both signals for the rest of its life. Register the signal listeners with once() and re-raise the signal after cleanup when nothing else listens for it, so the default exit still happens. When the application has its own listener it keeps handling the signal as before.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The span cache registers
SIGINTandSIGTERMlisteners the first time it opens its temp file (registerExitHandlerinjs/src/span-cache.ts). Node only exits on those signals by default while nothing listens for them, so after the firstEval()the process stops responding to Ctrl+C and toSIGTERMfor the rest of its life. That matters for anything long running that callsEval(): a server, a watch loop, or a container that getsSIGTERMon shutdown and is then killed after the grace period.Repro, run with
node --import tsxfromjs/:On main it prints
still alive 2s after SIGTERM. With this change the process exits on theSIGTERM.The signal listeners are now registered with
once(), clean up as before, and then re-raise the signal when no other listener is left, so Node's default exit runs. If the application has its ownSIGINTorSIGTERMlistener, nothing is re-raised and it keeps handling the signal itself, which is how it behaved without the SDK.Added
js/src/span-cache-signals.test.ts, which fails on main (the listener is still attached after it runs andprocess.killis never called) and passes here.span-cache.test.tsandspan-cache-flush-failure.test.tsstill pass, andpnpm run check:typingsand prettier are clean. Changeset included.