From d32dfdae347099c9043add5bb062882f2d415b3d Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Wed, 16 Oct 2019 17:28:34 -0400 Subject: [PATCH] Improve error when socket ValueTask consumed incorrectly (dotnet/corefx#41831) * Improve error when socket ValueTask consumed incorrectly * Update src/System.Net.Sockets/src/Resources/Strings.resx Co-Authored-By: David Shulman Commit migrated from https://github.com/dotnet/corefx/commit/a60703d66f0a75a6bb05d584b7677d9b04edf46a --- src/libraries/System.Net.Sockets/src/Resources/Strings.resx | 3 +++ .../System.Net.Sockets/src/System/Net/Sockets/Socket.Tasks.cs | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Net.Sockets/src/Resources/Strings.resx b/src/libraries/System.Net.Sockets/src/Resources/Strings.resx index 547bb2c..cad4341 100644 --- a/src/libraries/System.Net.Sockets/src/Resources/Strings.resx +++ b/src/libraries/System.Net.Sockets/src/Resources/Strings.resx @@ -246,4 +246,7 @@ The FileStream must have been opened for asynchronous reading and writing. + + A ValueTask returned from an asynchronous socket operation was consumed concurrently. ValueTasks must only ever be awaited once. (Id: {0}). + diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Tasks.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Tasks.cs index 1dc7680..304f10a 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Tasks.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Tasks.cs @@ -811,9 +811,9 @@ namespace System.Net.Sockets { internal static readonly AwaitableSocketAsyncEventArgs Reserved = new AwaitableSocketAsyncEventArgs() { _continuation = null }; /// Sentinel object used to indicate that the operation has completed prior to OnCompleted being called. - private static readonly Action s_completedSentinel = new Action(state => throw new Exception(nameof(s_completedSentinel))); + private static readonly Action s_completedSentinel = new Action(state => throw new InvalidOperationException(SR.Format(SR.net_sockets_valuetaskmisuse, nameof(s_completedSentinel)))); /// Sentinel object used to indicate that the instance is available for use. - private static readonly Action s_availableSentinel = new Action(state => throw new Exception(nameof(s_availableSentinel))); + private static readonly Action s_availableSentinel = new Action(state => throw new InvalidOperationException(SR.Format(SR.net_sockets_valuetaskmisuse, nameof(s_availableSentinel)))); /// /// if the object is available for use, after GetResult has been called on a previous use. /// null if the operation has not completed. -- 2.7.4