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

Commit

Permalink
Improve error when socket ValueTask consumed incorrectly (#41831)
Browse files Browse the repository at this point in the history
* Improve error when socket ValueTask consumed incorrectly

* Update src/System.Net.Sockets/src/Resources/Strings.resx

Co-Authored-By: David Shulman <david.shulman@microsoft.com>
  • Loading branch information
2 people authored and safern committed Oct 16, 2019
1 parent ba76ea2 commit a60703d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/System.Net.Sockets/src/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,7 @@
<data name="net_sockets_sendpackelement_FileStreamMustBeAsync" xml:space="preserve">
<value>The FileStream must have been opened for asynchronous reading and writing.</value>
</data>
<data name="net_sockets_valuetaskmisuse" xml:space="preserve">
<value>A ValueTask returned from an asynchronous socket operation was consumed concurrently. ValueTasks must only ever be awaited once. (Id: {0}).</value>
</data>
</root>
4 changes: 2 additions & 2 deletions src/System.Net.Sockets/src/System/Net/Sockets/Socket.Tasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -811,9 +811,9 @@ internal sealed class AwaitableSocketAsyncEventArgs : SocketAsyncEventArgs, IVal
{
internal static readonly AwaitableSocketAsyncEventArgs Reserved = new AwaitableSocketAsyncEventArgs() { _continuation = null };
/// <summary>Sentinel object used to indicate that the operation has completed prior to OnCompleted being called.</summary>
private static readonly Action<object> s_completedSentinel = new Action<object>(state => throw new Exception(nameof(s_completedSentinel)));
private static readonly Action<object> s_completedSentinel = new Action<object>(state => throw new InvalidOperationException(SR.Format(SR.net_sockets_valuetaskmisuse, nameof(s_completedSentinel))));
/// <summary>Sentinel object used to indicate that the instance is available for use.</summary>
private static readonly Action<object> s_availableSentinel = new Action<object>(state => throw new Exception(nameof(s_availableSentinel)));
private static readonly Action<object> s_availableSentinel = new Action<object>(state => throw new InvalidOperationException(SR.Format(SR.net_sockets_valuetaskmisuse, nameof(s_availableSentinel))));
/// <summary>
/// <see cref="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.
Expand Down

0 comments on commit a60703d

Please sign in to comment.