Skip to content

Socket.SendTo/ReceiveFrom crash when send/receive timeouts are set #1

Open

Description

@misenhower

I noticed a crash when using SendTo and ReceiveFrom with sockets that have SendTimeout or ReceiveTimeout values set. As an example, the following code throws an ArgumentOutOfRange exception:

// Wait for DHCP
while (IPAddress.GetDefaultLocalAddress() == IPAddress.Any)
    Thread.Sleep(50);

// Set up a sample IP endpoint
IPAddress ip = Dns.GetHostEntry("time-a.nist.gov").AddressList[0];
EndPoint remoteEndPoint = new IPEndPoint(ip, 123);

// Set up a send/receive buffer with sample data
byte[] buffer = new byte[48];
buffer[0] = 0x1B;

using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp))
{
    socket.SendTimeout = 1000;
    socket.ReceiveTimeout = 1000;

    socket.SendTo(buffer, remoteEndPoint);
    socket.ReceiveFrom(buffer, ref remoteEndPoint);
}

If you comment out the SendTimeout line, the call to SendTo completes successfully. Similarly, commenting out the ReceiveTimeout line makes the ReceiveFrom call complete successfully.

This issue does not appear to be present when using the Send/Receive methods.

Please let me know if you need any more information. Thanks!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions