From e2356e37eeea7cdd7087ea9afe70ddca2a3c7599 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Mon, 4 Nov 2019 16:34:25 -0500 Subject: [PATCH] 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/System/Data/SqlClient/SNI/SNIPacket.NetCoreApp.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIPacket.NetCoreApp.cs b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIPacket.NetCoreApp.cs index 4d3955a..9a25f08 100644 --- a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIPacket.NetCoreApp.cs +++ b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIPacket.NetCoreApp.cs @@ -58,6 +58,11 @@ namespace System.Data.SqlClient.SNI // Completed return; } + else + { + // Avoid consuming the same instance twice. + vt = new ValueTask(_dataLength); + } } // Not complete or error call the async local function to complete -- 2.7.4