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

Improve error when socket ValueTask consumed incorrectly #41831

Merged
merged 2 commits into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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