Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Fix SNIPacket.ReadFromStreamAsync to not consume same ValueTask twice #42338

Merged
merged 1 commit into from
Nov 4, 2019

Conversation

stephentoub
Copy link
Member

Found via an analyzer I'm working on for ValueTasks.

This calls stream.ReadAsync, and in the case where the ValueTask completes successfully by the time the code checks and where the returned Result <= 0, it then awaits the ValueTask again, representing a second consumption when only one is considered legal.

Fix it by replacing the original ValueTask with a new one containing the same result.

Found via an analyzer I'm working on for ValueTasks.

This calls stream.ReadAsync, and in the case where the ValueTask completes successfully by the time the code checks and where the returned Result <= 0, it then awaits the ValueTask again, representing a second consumption when only one is considered legal.

Fix it by replacing the original ValueTask with a new one containing the same result.
Copy link

@scalablecory scalablecory left a comment

Choose a reason for hiding this comment

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

looking forward to your analyzer :)

@davidsh davidsh added this to the 5.0 milestone Nov 4, 2019
@roji
Copy link
Member

roji commented Nov 4, 2019

/cc @cheenamalhotra @David-Engel @Wraith2

This should probably be replicated into https://github.com/dotnet/sqlclient.

@stephentoub
Copy link
Member Author

This should probably be replicated into https://github.com/dotnet/sqlclient

Yup.
dotnet/SqlClient#295

@stephentoub stephentoub merged commit a7cebb9 into dotnet:master Nov 4, 2019
@stephentoub stephentoub deleted the fixsqlvaluetask branch November 4, 2019 21:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants