Skip to content

[Tools] Wait for Android JDWP application readiness - #12589

Closed
davidnguyen-tech wants to merge 2 commits into
dotnet:mainfrom
davidnguyen-tech:davidnguyen-tech/jdwp-stag-readiness
Closed

davidnguyen-tech wants to merge 2 commits into
dotnet:mainfrom
davidnguyen-tech:davidnguyen-tech/jdwp-stag-readiness

Conversation

@davidnguyen-tech

@davidnguyen-tech davidnguyen-tech commented Aug 30, 2026 •

Copy link
Copy Markdown
Member

Status

Discontinued on 2026-09-01. The product-compatible preview backport was
validated downstream, but three exact consumer campaigns (15165979,
15165980, and 15165981) ended at 0/3 because Android remained at the Java
debugger gate. The investigation has moved to managed-only debugging with
_AndroidAllowJavaDebugging=false and transient am set-debug-app without
-w. Java-debugging opt-in is no longer a required outcome, so this proposal
is closing unmerged.

Original proposal

Android can acknowledge a temporary JDWP connection before Debug.waitForDebugger() has advanced far enough for the application to continue reliably. Keeping the connection open for a fixed delay hides that race on newer runtimes and provides no protocol evidence that startup is ready.

This change extends the existing JDWP packet path to:

  • request DDM HELO and FEAT;
  • use the runtime-advertised support_boot_stages capability instead of assuming support from the API level;
  • treat DEBG as a pre-gate state and wait for a sticky A_GO snapshot or STAG transition;
  • retain the existing 1400 ms compatibility hold after a successful FEAT response that does not advertise boot stages; and
  • enforce one 10-second bound across capability negotiation, stage waiting, and the legacy hold.

Protocol failures fail closed. Caller cancellation and readiness timeout close an in-flight stream read, preserve distinct OperationCanceledException and TimeoutException behavior, and leave forwarded-port cleanup unchanged.

  • Useful description of why the change is necessary.
  • Links to issues fixed
  • Unit tests

The deterministic tests cover pre-gate DEBG, transition to A_GO, out-of-order STAG before a stale HELO snapshot, timeout with a non-cooperative read, caller cancellation, FEAT failure, and the legacy fallback. The focused suite passes 6/6.

Use DDM boot-stage capability and STAG updates to hold the temporary JDWP connection until A_GO, with a bounded legacy fallback and deterministic protocol tests.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 3c573669-b4d3-4441-85ee-5a906a62b6f7
@davidnguyen-tech

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@jonathanpeppers

Copy link
Copy Markdown
Member

@davidnguyen-tech FYI, I was reviewing the history on this JDWP connection. It appears to have been a workaround added for Android Subsystem for Windows, which is now retired/end-of-life.

I want to just delete all this code in .NET 12, and didn't want to touch for 11 at this point unless there is a problem.

I believe this code path is actually only used in Visual Studio, so not if you do dotnet run or dotnet build -t:Run. Were you seeing a problem with this somewhere?

Align the protocol-aware readiness deadline with the existing debugger launch timeout and report privacy-safe FEAT, HELO, STAG, completion, fallback, timeout, cancellation, and protocol-error milestones.

Co-authored-by: Copilot App <[email protected]>
@davidnguyen-tech

davidnguyen-tech commented Sep 1, 2026 •

Copy link
Copy Markdown
Member Author

Closing for #12625

jonathanpeppers added a commit that referenced this pull request Sep 1, 2026
## Why

This is a smaller alternative to #12589 for the pre-runtime **Waiting For Debugger** race seen in the VS Code MAUI F5 path. The extension launches Android apps through `dotnet build -t:Run` with `AndroidAttachDebugger=true`. Today, `_Run` defaults Java debugging on, which adds `am start -D`, opens a temporary JDWP connection through `ConnectJdwpAsync()`, and relies on the `Android.Debug.waitForDebugger()` gate. That JDWP startup sequence can race before the managed runtime is ready.

VS Code only needs managed debugging for this scenario. Defaulting `$(_AndroidAllowJavaDebugging)` to `False` bypasses the JDWP connection and wait gate entirely, while preserving `$(_AndroidAllowJavaDebugging)=True` as an explicit opt-in.

The JDWP path appears to have originated as a workaround for Windows Subsystem for Android, which is now retired. Rather than add more JDWP readiness protocol handling to .NET 11, this keeps the .NET 11 change minimal ahead of removing the obsolete path in .NET 12.

This addresses the pre-runtime wait race only; it does not address the separate post-runtime RemoteCoreCLR EventStream race.

Co-authored-by: Copilot App <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants