Skip to content

Commit a88079c

Browse files
Copilotdrewnoakes
andcommitted
Remove test that doesn't reliably reproduce the race condition
The test for DisposedSocketDoesNotCauseInfiniteLoop doesn't reliably reproduce the specific race condition fixed in Mailbox.TryRecv (disposal during send with m_active=true). The fix (catching only SocketException instead of all exceptions) is straightforward and best verified through code review of Mailbox.TryRecv. Co-authored-by: drewnoakes <[email protected]>
1 parent 933c7f6 commit a88079c

File tree

1 file changed

+1
-39
lines changed

1 file changed

+1
-39
lines changed

src/NetMQ.Tests/ReqRepTests.cs

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
2-
using System.Threading;
3-
using System.Threading.Tasks;
4-
using NetMQ.Sockets;
1+
using NetMQ.Sockets;
52
using Xunit;
63

74
namespace NetMQ.Tests
@@ -285,40 +282,5 @@ public void SendMultipartMessageSucceeds()
285282
Assert.Equal(new[] { "Hello", "Back" }, req.ReceiveMultipartStrings());
286283
}
287284
}
288-
289-
[Fact]
290-
public async Task DisposedSocketDoesNotCauseInfiniteLoop()
291-
{
292-
// This test validates that when a socket is disposed while a send operation is in progress,
293-
// it doesn't cause an infinite loop in TrySend. The fix ensures that Mailbox.TryRecv only
294-
// catches SocketException and not ObjectDisposedException, allowing the exception to propagate
295-
// and break out of the sending loop.
296-
297-
var req = new RequestSocket();
298-
req.Options.Linger = TimeSpan.Zero;
299-
300-
// Connect to an endpoint that has no peer - this will cause sends to block
301-
req.Connect("tcp://localhost:15555");
302-
303-
// Dispose the socket to trigger ObjectDisposedException
304-
req.Dispose();
305-
306-
// Create a task that will attempt to send on the disposed socket
307-
// This should complete quickly by throwing an exception rather than hanging
308-
var sendTask = Task.Run(() =>
309-
{
310-
var msg = new NetMQMessage();
311-
msg.Append("test");
312-
req.SendMultipartMessage(msg);
313-
});
314-
315-
// If the fix is working, this should complete quickly (within 5 seconds)
316-
// If there's an infinite loop, it will timeout
317-
// The task may complete with an exception (which is fine - we just want it to complete)
318-
var timeoutTask = Task.Delay(TimeSpan.FromSeconds(5));
319-
var completedTask = await Task.WhenAny(sendTask, timeoutTask);
320-
321-
Assert.True(completedTask == sendTask, "Send operation should complete quickly after disposal, not hang in infinite loop");
322-
}
323285
}
324286
}

0 commit comments

Comments
 (0)