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 46fecd795ecd3c..d6ce3b64a2cc51 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
@@ -857,7 +857,7 @@ internal sealed class AwaitableSocketAsyncEventArgs : SocketAsyncEventArgs, IVal
/// if it has completed. Another delegate if OnCompleted was called before the operation could complete,
/// in which case it's the delegate to invoke when the operation does complete.
///
- private Action? _continuation;
+ private volatile Action? _continuation;
private ExecutionContext? _executionContext;
private object? _scheduler;
/// Current token value given to a ValueTask and then verified against the value it passes back to us.
@@ -930,7 +930,7 @@ protected override void OnCompleted(SocketAsyncEventArgs _)
/// This instance.
public ValueTask AcceptAsync(Socket socket, CancellationToken cancellationToken)
{
- Debug.Assert(Volatile.Read(ref _continuation) == null, "Expected null continuation to indicate reserved for use");
+ Debug.Assert(_continuation == null, "Expected null continuation to indicate reserved for use");
if (socket.AcceptAsync(this, cancellationToken))
{
@@ -952,7 +952,7 @@ public ValueTask AcceptAsync(Socket socket, CancellationToken cancellati
/// This instance.
public ValueTask ReceiveAsync(Socket socket, CancellationToken cancellationToken)
{
- Debug.Assert(Volatile.Read(ref _continuation) == null, "Expected null continuation to indicate reserved for use");
+ Debug.Assert(_continuation == null, "Expected null continuation to indicate reserved for use");
if (socket.ReceiveAsync(this, cancellationToken))
{
@@ -972,7 +972,7 @@ public ValueTask ReceiveAsync(Socket socket, CancellationToken cancellation
public ValueTask ReceiveFromAsync(Socket socket, CancellationToken cancellationToken)
{
- Debug.Assert(Volatile.Read(ref _continuation) == null, "Expected null continuation to indicate reserved for use");
+ Debug.Assert(_continuation == null, "Expected null continuation to indicate reserved for use");
if (socket.ReceiveFromAsync(this, cancellationToken))
{
@@ -993,7 +993,7 @@ public ValueTask ReceiveFromAsync(Socket socket, Cancel
public ValueTask ReceiveMessageFromAsync(Socket socket, CancellationToken cancellationToken)
{
- Debug.Assert(Volatile.Read(ref _continuation) == null, "Expected null continuation to indicate reserved for use");
+ Debug.Assert(_continuation == null, "Expected null continuation to indicate reserved for use");
if (socket.ReceiveMessageFromAsync(this, cancellationToken))
{
@@ -1018,7 +1018,7 @@ public ValueTask ReceiveMessageFromAsync(Socket
/// This instance.
public ValueTask SendAsync(Socket socket, CancellationToken cancellationToken)
{
- Debug.Assert(Volatile.Read(ref _continuation) == null, "Expected null continuation to indicate reserved for use");
+ Debug.Assert(_continuation == null, "Expected null continuation to indicate reserved for use");
if (socket.SendAsync(this, cancellationToken))
{
@@ -1038,7 +1038,7 @@ public ValueTask SendAsync(Socket socket, CancellationToken cancellationTok
public ValueTask SendAsyncForNetworkStream(Socket socket, CancellationToken cancellationToken)
{
- Debug.Assert(Volatile.Read(ref _continuation) == null, "Expected null continuation to indicate reserved for use");
+ Debug.Assert(_continuation == null, "Expected null continuation to indicate reserved for use");
if (socket.SendAsync(this, cancellationToken))
{
@@ -1057,7 +1057,7 @@ public ValueTask SendAsyncForNetworkStream(Socket socket, CancellationToken canc
public ValueTask SendPacketsAsync(Socket socket, CancellationToken cancellationToken)
{
- Debug.Assert(Volatile.Read(ref _continuation) == null, "Expected null continuation to indicate reserved for use");
+ Debug.Assert(_continuation == null, "Expected null continuation to indicate reserved for use");
if (socket.SendPacketsAsync(this, cancellationToken))
{
@@ -1076,7 +1076,7 @@ public ValueTask SendPacketsAsync(Socket socket, CancellationToken cancellationT
public ValueTask SendToAsync(Socket socket, CancellationToken cancellationToken)
{
- Debug.Assert(Volatile.Read(ref _continuation) == null, "Expected null continuation to indicate reserved for use");
+ Debug.Assert(_continuation == null, "Expected null continuation to indicate reserved for use");
if (socket.SendToAsync(this, cancellationToken))
{
@@ -1096,7 +1096,7 @@ public ValueTask SendToAsync(Socket socket, CancellationToken cancellationT
public ValueTask ConnectAsync(Socket socket)
{
- Debug.Assert(Volatile.Read(ref _continuation) == null, "Expected null continuation to indicate reserved for use");
+ Debug.Assert(_continuation == null, "Expected null continuation to indicate reserved for use");
try
{
@@ -1122,7 +1122,7 @@ public ValueTask ConnectAsync(Socket socket)
public ValueTask DisconnectAsync(Socket socket, CancellationToken cancellationToken)
{
- Debug.Assert(Volatile.Read(ref _continuation) == null, $"Expected null continuation to indicate reserved for use");
+ Debug.Assert(_continuation == null, $"Expected null continuation to indicate reserved for use");
if (socket.DisconnectAsync(this, cancellationToken))
{