[watch aspire] Suppress OperationCanceledException in StartChannelReader on shutdown#55242
Merged
Merged
Conversation
…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
tmat
approved these changes
Jul 10, 2026
Contributor
There was a problem hiding this comment.
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
OperationCanceledExceptionseparately inStartChannelReaderso cancellation during shutdown doesn’t produce an error log. - Simplify the remaining exception path to always log genuinely unexpected failures.
DustinCampbell
approved these changes
Jul 10, 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.
On Ctrl+C,
dotnet watchwas logging a spurious❌ Unexpected error reading output of sessiondue to aTaskCanceledExceptionthat should have been silently ignored.Root cause
StartChannelReaderreceivesrunningProject.Process.ExitedCancellationToken(cancelled only when the child process exits). It guarded against false-positive error logs by checking!cancellationToken.IsCancellationRequested. However,SendMessageAsyncinternally 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
onExitcallback in the same method: