Fix SNIPacket.ReadFromStreamAsync to not consume same ValueTask twice (dotnet/corefx...
authorStephen Toub <stoub@microsoft.com>
Mon, 4 Nov 2019 21:34:25 +0000 (16:34 -0500)
committerGitHub <noreply@github.com>
Mon, 4 Nov 2019 21:34:25 +0000 (16:34 -0500)
commite2356e37eeea7cdd7087ea9afe70ddca2a3c7599
tree739bb6ce1ef0c4e848d0bb6285d5f11ee071e97e
parent134e9d93c20cc0393f1aac99dffef4c77b8d7171
Fix SNIPacket.ReadFromStreamAsync to not consume same ValueTask twice (dotnet/corefx#42338)

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.

Commit migrated from https://github.com/dotnet/corefx/commit/a7cebb9ce454be31a0467ed418a221e5e3009768
src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIPacket.NetCoreApp.cs