-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Socket.Dispose() hangs on Mac when invoked concurrently with a blocking Receive(Message)From #47342
Comments
Tagging subscribers to this area: @dotnet/ncl Issue DetailsDiscovered while implementing tests for #47229. While on Windows and Linux Repro codeprivate static async Task DisposeDuringPendingReceiveFrom_UDP(bool receiveMessageFrom)
{
using var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
socket.Bind(new IPEndPoint(IPAddress.Any, 0));
EndPoint testEndpoint = new IPEndPoint(IPAddress.Parse("1.2.3.4"), 1234);
void DoReceiveFrom()
{
try
{
if (receiveMessageFrom)
{
var flags = SocketFlags.None;
socket.ReceiveMessageFrom(new byte[128], 0, 128, ref flags, ref testEndpoint, out _);
}
else
{
socket.ReceiveFrom(new byte[128], ref testEndpoint);
}
}
catch (Exception ex)
{
Console.WriteLine($"ABORTED! {ex.GetType().Name} : {ex.Message}");
}
}
Console.WriteLine("Starting operation...");
Task receiveTask = Task.Run(DoReceiveFrom);
await Task.Delay(200);
Console.WriteLine("Disposing...");
socket.Dispose(); // HANGS HERE
var timeoutTask = Task.Delay(5000);
Console.WriteLine("Waiting for operation...");
if (Task.WhenAny(receiveTask, timeoutTask) == timeoutTask)
{
Console.WriteLine("TIMEOUT!!!");
}
} DumpDump
|
Triage: It is deadlock (or waiting for another packet) on Mac (development scenario) using UDP (which is not super common). Does not affect TCP, which is already fixed -- Idea: Can we reuse TCP solution in UDP as well? Until we have hits from customers / high impact on CI, moving to Future. |
Hi, same issue for me. I develop my own udp lib under MacOs and after the call Could you suggest any workaround? |
@rdcm I recommend to go async with either the task-based or the |
It seems like we did not find a way how to do this on macOS, right @tmds? |
This seems like dup of #64551. While this is older, the other issue has more discussion in it. So perhaps we can close this one instead @antonfirsov ? |
Duplicate of #64551. |
Discovered while implementing tests for #47229.
While on Windows and Linux
Socket.Dispose/Close
will abort a concurrent blockingReceiveFrom
orReceiveMessageFrom
call, on Mac it leads to a hang. The issue is not present with TCP receives.Edit: Shutdown leads to the same result.
Repro code
Dump
Dump
The text was updated successfully, but these errors were encountered: