Skip to content

Commit fe9795f

Browse files
committed
Reset the SocketAsyncEventArgs.in_progress flag after failure
When a DNS error occurs the flag needs to be reset before the Args object is put back in the queue for reuse. Failure to do so causes an "Operation already in progress" exception on a future request. Fixes Bee.Stevedore.Program.Tests.StevedoreTelemetryTests.SendOutbox_GoodServer_EventsSentInSingleBatch in Unity
1 parent 400643d commit fe9795f

File tree

1 file changed

+20
-2
lines changed
  • mcs/class/referencesource/System/net/System/Net/Sockets

1 file changed

+20
-2
lines changed

mcs/class/referencesource/System/net/System/Net/Sockets/Socket.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7782,7 +7782,16 @@ public bool ConnectAsync(SocketAsyncEventArgs e) {
77827782
e.StartOperationCommon(this);
77837783
e.StartOperationWrapperConnect(multipleConnectAsync);
77847784

7785-
retval = multipleConnectAsync.StartConnectAsync(e, dnsEP);
7785+
try
7786+
{
7787+
retval = multipleConnectAsync.StartConnectAsync(e, dnsEP);
7788+
}
7789+
catch
7790+
{
7791+
// Clear in-use flag on event args object.
7792+
Interlocked.Exchange(ref e.in_progress, 0);
7793+
throw;
7794+
}
77867795
}
77877796
else {
77887797
// Throw if remote address family doesn't match socket.
@@ -7880,7 +7889,16 @@ public static bool ConnectAsync(SocketType socketType, ProtocolType protocolType
78807889
e.StartOperationCommon(attemptSocket);
78817890
e.StartOperationWrapperConnect(multipleConnectAsync);
78827891

7883-
retval = multipleConnectAsync.StartConnectAsync(e, dnsEP);
7892+
try
7893+
{
7894+
retval = multipleConnectAsync.StartConnectAsync(e, dnsEP);
7895+
}
7896+
catch
7897+
{
7898+
// Clear in-use flag on event args object.
7899+
Interlocked.Exchange(ref e.in_progress, 0);
7900+
throw;
7901+
}
78847902
} else {
78857903
Socket attemptSocket = new Socket(endPointSnapshot.AddressFamily, socketType, protocolType);
78867904
retval = attemptSocket.ConnectAsync(e);

0 commit comments

Comments
 (0)