src: add --trace-sigterm to print a stack trace on SIGTERM - #64948
Open
orgads wants to merge 1 commit into
Open
Conversation
Collaborator
|
Review requested:
|
orgads
force-pushed
the
trace-sigterm
branch
2 times, most recently
from
August 2, 2026 06:16
294ed9f to
9124e14
Compare
Neither `--report-on-signal` nor a `process.on('SIGTERM')` handler runs
while JavaScript is stuck, which is exactly when a trace is wanted: a
pod whose liveness probe stopped responding gets terminated with
SIGTERM, and there is currently no way to find out where it was stuck.
Print the stack trace from an interrupt instead, like `--trace-sigint`
does. The signal is watched through libuv on a dedicated thread and
event loop rather than through a signal handler of our own, so that it
stays multiplexed with `process.on('SIGTERM')` handlers: applications
that shut down gracefully are the ones most likely to have a handler
installed, and disabling the trace for them would defeat the purpose.
Watching the signal takes its default disposition away, so restore it
and re-raise once the trace has been printed, unless the application
handles SIGTERM itself, in which case libuv has already delivered the
signal to its handler as well.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Fixes: nodejs#56879
Signed-off-by: Orgad Shaneh <orgad.shaneh@audiocodes.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #64948 +/- ##
==========================================
- Coverage 90.28% 90.28% -0.01%
==========================================
Files 760 760
Lines 247137 247192 +55
Branches 46617 46626 +9
==========================================
+ Hits 223122 223169 +47
- Misses 15493 15513 +20
+ Partials 8522 8510 -12
🚀 New features to boost your workflow:
|
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.
Neither
--report-on-signalnor aprocess.on('SIGTERM')handler runs while JavaScript is stuck, which is exactly when a trace is wanted: a pod whose liveness probe stopped responding gets terminated with SIGTERM, and there is currently no way to find out where it was stuck.Print the stack trace from an interrupt instead, like
--trace-sigintdoes. The signal is watched through libuv on a dedicated thread and event loop rather than through a signal handler of our own, so that it stays multiplexed withprocess.on('SIGTERM')handlers: applications that shut down gracefully are the ones most likely to have a handler installed, and disabling the trace for them would defeat the purpose.Watching the signal takes its default disposition away, so restore it and re-raise once the trace has been printed, unless the application handles SIGTERM itself, in which case libuv has already delivered the signal to its handler as well.
Fixes: #56879