Skip to content

Fix JSON-RPC error on disconnect and auto-restart Aspire debug session on AppHost restart#14548

Merged
adamint merged 3 commits intodotnet:mainfrom
adamint:dev/adamint/fix-debug-session-restart
Feb 25, 2026
Merged

Fix JSON-RPC error on disconnect and auto-restart Aspire debug session on AppHost restart#14548
adamint merged 3 commits intodotnet:mainfrom
adamint:dev/adamint/fix-debug-session-restart

Conversation

@adamint
Copy link
Member

@adamint adamint commented Feb 18, 2026

Description

This PR fixes two issues in the Aspire VS Code extension debug session:

  1. Fixed unexpected JSON-RPC connection lost error on debug session disconnect: When stopping or restarting the Aspire debug session, the CLI process is killed which closes the JSON-RPC connection. Previously this triggered an error notification to the user. Now, stopCli() failures during dispose are caught and logged gracefully, and the dispose() method is guarded against double-disposal to prevent redundant stopCli calls.

  2. Restarting the AppHost resource now restarts the Aspire debug session: Previously, when the AppHost debug session terminated (e.g., due to a resource restart), the Aspire debug session would simply dispose without restarting. Now, if the AppHost terminates and the stop was not user-initiated (i.e., the user didn't explicitly disconnect), the Aspire debug session automatically restarts by launching a new debug session with the same configuration.

(Tested manually. The unexpected JSON-RPC connection lost error was happening on every restart before)

Changes

  • Added _disposed flag to prevent double-disposal of the debug session
  • Added _userInitiatedStop flag to distinguish user-initiated stops from AppHost-initiated terminations
  • Wrapped stopCli() call in error handler since the connection may already be closed during dispose
  • Removed duplicate stopCli() call from dispose() (already handled by disposables)
  • When AppHost terminates unexpectedly (not user-initiated), automatically restart the Aspire debug session

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

@github-actions
Copy link
Contributor

github-actions bot commented Feb 18, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 14548

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 14548"

@adamint adamint marked this pull request as ready for review February 18, 2026 18:17
Copilot AI review requested due to automatic review settings February 18, 2026 18:17
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the Aspire VS Code extension debug session to fix JSON-RPC connection errors during disconnect and to automatically restart debug sessions when the AppHost terminates unexpectedly.

Changes:

  • Added double-disposal protection with a _disposed flag
  • Implemented auto-restart functionality for AppHost crashes using a _userInitiatedStop flag to distinguish user-initiated stops from system failures
  • Improved error handling for stopCli() calls by catching and logging failures gracefully

Comment on lines +227 to +228
const shouldRestart = !this._userInitiatedStop;
const config = this.configuration;
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The configuration should be captured before calling dispose() to avoid potential issues. While the configuration is captured into a local variable before dispose is called, the order of operations could be clearer. Consider capturing the configuration at the start of the if block (line 226) before any other operations.

Suggested change
const shouldRestart = !this._userInitiatedStop;
const config = this.configuration;
const config = this.configuration;
const shouldRestart = !this._userInitiatedStop;

Copilot uses AI. Check for mistakes.
adamint and others added 2 commits February 18, 2026 12:55
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@adamint adamint merged commit 1ffb9bb into dotnet:main Feb 25, 2026
343 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the 13.3 milestone Feb 25, 2026
adamint added a commit to adamint/aspire that referenced this pull request Mar 2, 2026
…n on AppHost restart (dotnet#14548)

* Fix JSON-RPC error on disconnect and auto-restart debug session on AppHost restart

* Update extension/src/debugger/AspireDebugSession.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update extension/src/debugger/AspireDebugSession.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
adamint added a commit that referenced this pull request Mar 2, 2026
* Detect CLI at default install paths when not on PATH (#14545)

Check default installation directories (~/.aspire/bin, ~/.dotnet/tools) when the
Aspire CLI is not found on the system PATH. If found at a default location, the
VS Code setting is auto-updated. If later found on PATH, the setting is cleared.

Resolution order: configured custom path > system PATH > default install paths.

Fixes #14235

* Fix JSON-RPC error on disconnect and auto-restart Aspire debug session on AppHost restart (#14548)

* Fix JSON-RPC error on disconnect and auto-restart debug session on AppHost restart

* Update extension/src/debugger/AspireDebugSession.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update extension/src/debugger/AspireDebugSession.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

3 participants