fix: address review comments - guard redundant STW requests, add bootstrap pause VM switch

This commit is contained in:
Alistair Smith
2026-02-10 02:16:36 -08:00
parent c27dd9048c
commit e56a08d58d
2 changed files with 23 additions and 2 deletions

View File

@@ -786,6 +786,23 @@ bool hasBootstrapPauseRequested()
return false;
}
// Find a VM (other than the given one) that has a bootstrap pause pending.
JSC::VM* findVMWithBootstrapPause(JSC::VM& excludeVM)
{
Locker<Lock> locker(inspectorConnectionsLock);
if (!inspectorConnections)
return nullptr;
for (auto& entry : *inspectorConnections) {
for (auto* connection : entry.value) {
if (connection->needsBootstrapPause.load()
&& connection->globalObject
&& &connection->globalObject->vm() != &excludeVM)
return &connection->globalObject->vm();
}
}
return nullptr;
}
// Schedule a debugger pause for connected sessions.
// Called during STW after doConnect has already attached the debugger.
// schedulePauseAtNextOpportunity + notifyNeedDebuggerBreak set up a pause
@@ -841,10 +858,12 @@ JSC::StopTheWorldStatus Bun__jsDebuggerCallback(JSC::VM& vm, JSC::StopTheWorldEv
// doConnect must run on the connection's owning VM thread.
bool connected = Bun::processPendingConnections(vm);
// If pending connections exist on a DIFFERENT VM, switch to it.
// If pending connections or bootstrap pauses exist on a DIFFERENT VM, switch to it.
if (!connected) {
if (auto* targetVM = Bun::findVMWithPendingConnections(vm))
return STW_CONTEXT_SWITCH(targetVM);
if (auto* targetVM = Bun::findVMWithBootstrapPause(vm))
return STW_CONTEXT_SWITCH(targetVM);
}
// Phase 3: Schedule a debugger pause so CDP messages can be dispatched

View File

@@ -40,7 +40,9 @@ var inspector_activation_requested: std.atomic.Value(bool) = std.atomic.Value(bo
/// Called from the dedicated SignalInspector thread (POSIX) or remote thread (Windows).
/// This runs in normal thread context, so it's safe to call JSC APIs.
fn requestInspectorActivation() void {
inspector_activation_requested.store(true, .release);
// Avoid redundant STW requests if already requested but not yet consumed.
if (inspector_activation_requested.swap(true, .acq_rel))
return;
// Two mechanisms work together to handle all cases:
//