Hold a strong reference to DebuggerController in detached worker threads#1086
Merged
Conversation
The 17 `Launch`/`Attach`/`Connect`/`Go`/`Step*`/`RunTo*`/`Restart`/`Detach`/ `Quit`/`Pause` methods each spawn a detached `std::thread` that runs the corresponding `*AndWait` work, capturing `this` by reference. Nothing keeps the controller alive for the duration of the detached call, so if the controller's refcount drops to zero before the worker exits (e.g. the user closes the tab), the worker dereferences a dangling pointer. Capture a `DbgRef<DebuggerController>` by value into each lambda so the controller stays alive until the worker thread finishes. Fixes #1083. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced May 20, 2026
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.
Summary
DebuggerControllermethods that spawn a detached worker thread (Launch,Attach,Connect,Go,GoReverse,Step{Into,Over,Return}{,Reverse},RunTo{,Reverse},Restart,Detach,Quit,Pause) all capturedthisby reference, with nothing ensuring the refcounted controller stayed alive for the duration of the detached call.DbgRefwas dropped (e.g. the user closed the tab) before the worker finished, the worker would dereference a freedDebuggerController— that's the crash in Crash below DebuggerController::DetachAndWait #1083 (and the same shape as several other Sentry reports:RspConnector::SendRaw,DbgEngAdapter::ReadMemory, etc.).DbgRef<DebuggerController> self = this;and the lambda capturesselfby value, so the refcount reflects the running thread and the controller can't be destroyed under it.The constructor's
m_debuggerEventThread(line 41) is unchanged because it's stored as a member and joined explicitly in the destructor — already safe.Fixes #1083.
Test plan
ninja debuggercore)🤖 Generated with Claude Code