inspector: fix abort when two Environments own the inspector - #65877
Open
codebytere wants to merge 2 commits into
Open
inspector: fix abort when two Environments own the inspector#65877codebytere wants to merge 2 commits into
codebytere wants to merge 2 commits into
Conversation
Collaborator
|
Review requested:
|
Two Environments with default flags alive at the same time (for example the embedding.md example run on two threads, or two `CommonEnvironmentSetup`s) aborted the process: `Agent::Start()` bound one file-level static `uv_async_t` to the current Environment's loop for every Environment with `kOwnsInspector`, which `kDefaultFlags` implies, and CHECKed that nobody else had. Environments created one after another did not abort, but each ran `StartDebugSignalHandler()` again, which re-initialized the semaphore the watchdog waits on and spawned another detached watchdog thread, leaking one thread per Environment. Give every Agent that asks for the debug signal handler its own async handle, keep those Agents in a mutex-protected list that the watchdog (or the Windows remote thread) walks, and set the watchdog up once per process while still unblocking SIGUSR1 on each Environment's thread. The handle is heap-allocated, closed by the cleanup hook or `~Agent()`, whichever runs first, and freed by its close callback. A SIGUSR1 now reaches every Environment that asked for the handler, and no longer starts the inspector of one that passed `kNoStartDebugSignalHandler`. Refs: nodejs#25777 Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com>
`InitializeOncePerProcess()` without `kNoDefaultSignalHandling` calls `pthread_sigmask(SIG_SETMASK, ...)` with a set containing only SIGUSR1, which unblocks every signal the embedder had blocked on the calling thread. Say so in the flag's documentation. Refs: nodejs#44121 Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com>
codebytere
force-pushed
the
fix/embedder-inspector-sigusr1-per-agent
branch
from
September 7, 2026 12:43
83fbd4e to
b1848f1
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #65877 +/- ##
==========================================
- Coverage 92.40% 90.18% -2.22%
==========================================
Files 417 771 +354
Lines 188648 264922 +76274
Branches 28849 50311 +21462
==========================================
+ Hits 174320 238929 +64609
- Misses 13995 16971 +2976
- Partials 333 9022 +8689
🚀 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.
Two Environments with default flags that are alive at the same time abort the process on a CHECK in
Agent::Start()(thedoc/api/embedding.mdexample on two threads, or twoCommonEnvironmentSetups), and every default Environment created after the first leaks a detachedSignalInspectorthread. The SIGUSR1 "start the inspector io thread" state was a single file-leveluv_async_twith a uniqueness CHECK, and the watchdog setup ran once per Environment instead of once per process.Each Agent whose Environment enables the debug signal handler now gets its own async handle and registers in a list that the watchdog thread walks; the watchdog is set up once per process while SIGUSR1 is still unblocked on each Environment's thread, and an Environment created with
kNoStartDebugSignalHandleris no longer woken by another Environment's handler. The second commit documents in node.h that default signal handling also resets the calling thread's signal mask.Tests:
EnvironmentTest.MultipleEnvironmentsPerIsolatenow creates both Environments with default flags (aborted before); the inspector, debugger and snapshot suites pass andkill -USR1still opens the inspector.Refs: #25777
Refs: #44121
Disclosure: the code, tests and this description were written by Claude Code, directed and reviewed by @codebytere.