Skip to content

forward CancellationToken in StreamOutputFormatter - #65785

Open
mus65 wants to merge 4 commits into
dotnet:mainfrom
mus65:streamoutputformatter
Open

mus65 wants to merge 4 commits into
dotnet:mainfrom
mus65:streamoutputformatter

Conversation

@mus65

@mus65 mus65 commented Mar 15, 2026

Copy link
Copy Markdown

Forward CancellationToken in StreamOutputFormatter

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Description

This forwards the cancellationToken from the HttpContext in the StreamOutputFormatter so it properly reacts to a client disconnect.

Fixes #65493

@mus65
mus65 requested a review from a team as a code owner March 15, 2026 10:27
@github-actions github-actions Bot added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Mar 15, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Mar 15, 2026
@dotnet-policy-service dotnet-policy-service Bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Mar 22, 2026
@mus65
mus65 force-pushed the streamoutputformatter branch from 4fa6a8a to 3599c89 Compare March 22, 2026 16:41
@mus65
mus65 force-pushed the streamoutputformatter branch from 3599c89 to 90e97cf Compare April 21, 2026 16:00
@mus65

mus65 commented May 7, 2026

Copy link
Copy Markdown
Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Commenter does not have sufficient privileges for PR 65785 in repo dotnet/aspnetcore

@mus65 mus65 closed this May 7, 2026
@mus65 mus65 reopened this May 7, 2026
@dotnet-policy-service dotnet-policy-service Bot added this to the 11.0-preview5 milestone May 7, 2026
@Youssef1313 Youssef1313 modified the milestones: 11.0-preview7, 11.0-rc1 Aug 12, 2026
@Youssef1313 Youssef1313 removed this from the 11.0-rc1 milestone Aug 19, 2026
@Youssef1313 Youssef1313 self-assigned this Aug 19, 2026

@Youssef1313 Youssef1313 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@Youssef1313 Youssef1313 removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Aug 19, 2026
}

await valueAsStream.CopyToAsync(response.Body);
await valueAsStream.CopyToAsync(response.Body, context.HttpContext.RequestAborted);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I would actually prefer to throw so the exception handler middleware has a chance to log it.

I actually noticed that there is no way to detect an OCE when writing the response. When reading the request however, OCE seem to be thrown and logged properly.

Maybe open a separate issue for this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should change all formatters to not catch OCE caused by RequestAborted. And then make a note about breaking change in the docs. Consistency is better IMHO. what's your thoughts here, @BrennanConroy ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think a lot more discussion is needed before we start removing it from places that currently catch OCE.
See some context from past issues/discussions:
#35330
#38633
#44697

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service Bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Sep 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates community-contribution Indicates that the PR has been added by a community member pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StreamOutputFormatter doesn't react to client disconnect

4 participants