Skip to content

Consume ValueTask with GetAwaiter().GetResult() #29710

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

Merged
merged 2 commits into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Components/Components/src/Rendering/ComponentState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ public Task DisposeInBatchAsync(RenderBatchBuilder batchBuilder)
var result = ((IAsyncDisposable)Component).DisposeAsync();
if (result.IsCompletedSuccessfully)
{
// If it's a IValueTaskSource backed ValueTask,
// inform it its result has been read so it can reset
result.GetAwaiter().GetResult();
Copy link
Member

Choose a reason for hiding this comment

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

@davidfowl do we need to do this across all places where we consume ValueTask?

Copy link
Member

Choose a reason for hiding this comment

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

Yes. There's an uber issue with a bunch of violations in our code base wrt value task. @stephentoub filed the issue in 5.0 we should address those things in 6.0

Copy link
Member

Choose a reason for hiding this comment

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

Looks like it's #16876. Might as well go ahead and take this if someone wants to sign off on it.

return Task.CompletedTask;
}
else
Expand Down
4 changes: 4 additions & 0 deletions src/Servers/Kestrel/Core/src/Internal/Http2/Http2Stream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,10 @@ public Task OnDataAsync(Http2Frame dataFrame, in ReadOnlySequence<byte> payload)
// It shouldn't be possible for the RequestBodyPipe to fill up an return an incomplete task if
// _inputFlowControl.Advance() didn't throw.
Debug.Assert(flushTask.IsCompletedSuccessfully);

// If it's a IValueTaskSource backed ValueTask,
// inform it its result has been read so it can reset
flushTask.GetAwaiter().GetResult();
}
}
}
Expand Down