Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve abort handling #41263

Merged
merged 3 commits into from
Apr 20, 2022
Merged

Improve abort handling #41263

merged 3 commits into from
Apr 20, 2022

Conversation

HaoK
Copy link
Member

@HaoK HaoK commented Apr 19, 2022

Fixes #31404

@ghost ghost added the area-runtime label Apr 19, 2022
@@ -159,6 +159,11 @@ private async Task WriteBody(bool flush = false)
{
while (true)
{
if (_bodyOutput.Aborted)
{
break;
Copy link
Member Author

Choose a reason for hiding this comment

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

Not really sure this break here is ok, as I'm not really sure what the expectations are before/after this loop, is this what you had in mind @Tratcher ?

Copy link
Member Author

Choose a reason for hiding this comment

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

We have tests explicitly checking that Writes after abort no-op, so I don't think we want to throw exceptions right?

Copy link
Member

Choose a reason for hiding this comment

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

Right, Write shouldn't throw.

I think this check needs to be after ReadAsync or you'd miss an Abort that happened while waiting for data.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, there might be an issue if AdvanceTo isn't called? Moving this check inside the Try block would cover that with the finally.

Copy link
Member

Choose a reason for hiding this comment

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

Are we always calling Complete on the pipe? If we don't there's a memory leak.

@@ -159,6 +159,11 @@ private async Task WriteBody(bool flush = false)
{
while (true)
{
if (_bodyOutput.Aborted)
{
break;
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, there might be an issue if AdvanceTo isn't called? Moving this check inside the Try block would cover that with the finally.

@HaoK HaoK marked this pull request as ready for review April 19, 2022 23:17
@davidfowl
Copy link
Member

Hmm, there might be an issue if AdvanceTo isn't called? Moving this check inside the Try block would cover that with the finally.

You can skip AdvanceTo if you call Complete. Complete must always be called.

@HaoK
Copy link
Member Author

HaoK commented Apr 20, 2022

The complete call is in the finally outside of the while loop, so I think we are good there. So should we just break at the top? I think the only question is where this new check for aborted needs to go

@Tratcher
Copy link
Member

I think the current version is fine. The important part is that the abort check is after ReadAsync.

@HaoK HaoK merged commit c9af606 into main Apr 20, 2022
@HaoK HaoK deleted the haok/abort branch April 20, 2022 18:00
@ghost ghost added this to the 7.0-preview5 milestone Apr 20, 2022
@HaoK HaoK mentioned this pull request Apr 25, 2022
9 tasks
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Abort gracefully closes the response rather than aborting it
4 participants