Repository navigation
Fix remote debug adapter process lifecycle - #8650
Open
Stella Huang (StellaHuang95) wants to merge 1 commit into
Open
Stella Huang (StellaHuang95) wants to merge 1 commit into
Stella Huang (StellaHuang95) wants to merge 1 commit into
Conversation
Make remote attach lifecycle transitions thread-safe and idempotent, detect DAP and socket disconnects reliably, and cover timeout, failure, disposal, and concurrent exit paths with loopback tests. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 47b8fa60-3d73-4680-8781-5e56196aefc8
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
|
🔒 Automated review in progress — Heejae Chang (@heejaechang) is auto-reviewing this PR. |
Contributor
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
Result: 🔴 Verification detailsVerification: The relevant tests could not be fully run in the isolated environment; this review is not fully verified. Details: Verification could not complete: timeout must be None or at least 2073600 seconds (24 days); shorter completion deadlines are unsupported. Test runs: none recorded. |
Heejae Chang (heejaechang)
approved these changes
Oct 22, 2026
Heejae Chang (heejaechang)
left a comment
There was a problem hiding this comment.
Approved via Review Center.
Bill Schnurr (bschnurr)
approved these changes
Oct 22, 2026
Bill Schnurr (bschnurr)
left a comment
Member
There was a problem hiding this comment.
Approved via Review Center.
Rich Chiodo (rchiodo)
approved these changes
Oct 23, 2026
Rich Chiodo (rchiodo)
left a comment
Contributor
There was a problem hiding this comment.
Approved via Review Center.
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.



Summary
DebugAdapterRemoteProcess.HasExitedso a connected remote adapter is reported as running.Terminate, andDisposethrough one thread-safe/idempotent exit transition.Exited, and raiseExitedexactly once under concurrent close paths.JoinableTaskFactoryconnection wait while making timeout and socket-failure cleanup deterministic.disconnectresponses are recognized reliably.ITargetHostProcesscontract.Fixes #8305
Before / after
Before: a successful connection set
_debuggerConnected = true, andHasExitedreturned that value. Debug Adapter Host therefore saw the newly connected adapter as already exited. Disconnect/terminate/dispose paths independently disposed the stream, did not consistently update state, and could miss or duplicate lifecycle notification.After: connected means
HasExited == false. The first disconnect/terminate/dispose transition atomically marks the process exited, unsubscribes stream callbacks, disposes the transport, and raisesExited; later concurrent transitions are no-ops.Validation
Python\Tests\Core\PythonToolsTests.csprojwith VS 2022 MSBuild targeting VS 17.0.DebugAdapterRemoteProcessTestsplusLauncherTests: 15/15 passed.Manual remote debugpy attach
Ran:
The harness spawned:
Using Python 3.14.7 and debugpy 1.8.20, two sequential DAP attach sessions connected to the same live target process. Both sessions returned
MainThread, verified and hit the breakpoint at line 9, continued successfully, acknowledgeddisconnect, and emittedterminated. The target remained alive between sessions.Review notes
The final race/resource review covered state ordering, reentrant event handlers, concurrent read/dispose, UI-thread waits, timeout task observation, socket ownership, DAP fragmentation, parser bounds, and exception behavior. It found and fixed two issues before publication: restoring JTF-based production waiting to avoid a UI responsiveness regression, and resetting both length and position of the reusable DAP frame buffer between messages.
Residual risk
The manual test exercised the real debugpy adapter and target over loopback, while the committed tests exercise the exact
ITargetHostProcesstransport/lifecycle contract. A full Visual Studio experimental-instance Attach to Process UI run was not available in this environment.