Skip to content

Succesful Socket.Shutdown(Both) does not consistently lead to SocketException for a subsequent Receive(Message)From #47469

@antonfirsov

Description

@antonfirsov

Consider the following test case from #47229:

[Theory]
[InlineData(SocketShutdown.Receive)] // Works
[InlineData(SocketShutdown.Both)] // Sporadic failures
public async Task ShutdownReceiveBeforeOperation_ThrowsSocketException(SocketShutdown shutdown)
{
    using var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
    socket.BindToAnonymousPort(IPAddress.Any);
    socket.Shutdown(shutdown);

    SocketException exception = await Assert.ThrowsAnyAsync<SocketException>(() => ReceiveMessageFromAsync(socket, new byte[1], GetGetDummyTestEndpoint()))
        .TimeoutAfter(CancellationTestTimeout);

    Assert.Equal(SocketError.Shutdown, exception.SocketErrorCode);
}

The SocketShutdown.Both case seems to lead to intermittent timeouts on CI:
https://dev.azure.com/dnceng/public/_build/results?buildId=964879&view=ms.vss-test-web.build-test-results-tab&runId=30372566&resultId=161868&paneView=debug

Shutting down of UDP sockets is a very unusual thing to do, that doesn't even work on Unix, so we may end up closing this as wontfix, but I want to make sure the issue is documented and discussed. Also note that we do not have equivalent tests for the interaction between Shutdown and TCP Receive, so we may want to investigate if it's a more general problem not specific to UDP.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions