Skip to content

[watch aspire] Suppress OperationCanceledException in StartChannelReader on shutdown#55242

Merged
tmat merged 2 commits into
release/10.0.4xxfrom
copilot/watch-aspire-error-fix
Jul 10, 2026
Merged

[watch aspire] Suppress OperationCanceledException in StartChannelReader on shutdown#55242
tmat merged 2 commits into
release/10.0.4xxfrom
copilot/watch-aspire-error-fix

Conversation

Copilot AI commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

On Ctrl+C, dotnet watch was logging a spurious ❌ Unexpected error reading output of session due to a TaskCanceledException that should have been silently ignored.

Root cause

StartChannelReader receives runningProject.Process.ExitedCancellationToken (cancelled only when the child process exits). It guarded against false-positive error logs by checking !cancellationToken.IsCancellationRequested. However, SendMessageAsync internally builds a linked token from the passed token plus _shutdownCancellationSource.Token, so pressing Ctrl+C cancels the send while the process exit token is still live — causing the guard to miss the cancellation and log the error.

Fix

Replace the single catch + conditional log with two separate catches, matching the existing pattern used in the onExit callback in the same method:

// before
catch (Exception e)
{
    if (!cancellationToken.IsCancellationRequested)
    {
        _logger.LogError("Unexpected error reading output of session '{SessionId}': {Exception}", sessionId, e);
    }
}

// after
catch (OperationCanceledException)
{
    // canceled on shutdown, ignore
}
catch (Exception e)
{
    _logger.LogError("Unexpected error reading output of session '{SessionId}': {Exception}", sessionId, e);
}

…l+C shutdown

Co-authored-by: tmat <41759+tmat@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix cancellation error reported during watch session [watch aspire] Suppress OperationCanceledException in StartChannelReader on shutdown Jul 10, 2026
Copilot finished work on behalf of tmat July 10, 2026 20:15
Copilot AI requested a review from tmat July 10, 2026 20:15
@tmat tmat marked this pull request as ready for review July 10, 2026 20:29
@tmat tmat requested a review from a team as a code owner July 10, 2026 20:29
Copilot AI review requested due to automatic review settings July 10, 2026 20:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 adjusts dotnet watch Aspire session output handling to avoid logging a misleading “Unexpected error reading output of session …” message during shutdown (e.g., Ctrl+C), by explicitly suppressing cancellation exceptions from the channel reader loop.

Changes:

  • Handle OperationCanceledException separately in StartChannelReader so cancellation during shutdown doesn’t produce an error log.
  • Simplify the remaining exception path to always log genuinely unexpected failures.

Comment thread src/Dotnet.Watch/Watch/Aspire/AspireServiceFactory.cs
@tmat tmat enabled auto-merge (squash) July 10, 2026 21:47
@tmat tmat merged commit e2c64bc into release/10.0.4xx Jul 10, 2026
25 checks passed
@tmat tmat deleted the copilot/watch-aspire-error-fix branch July 10, 2026 21:55
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.

[watch aspire] Error reported on cancellation via Ctrl+C

4 participants