Skip to content

Net: Socket::available causes connection reset on Windows UDP sockets #4537

@andrewauclair

Description

@andrewauclair

Describe the bug
Created a DatagramSocket with local address 127.0.0.1:0 and remote address 127.0.0.1:2345. After calling sendBytes on this UDP socket, poll returns true, then available returns -1 and the last error is "connection reset by peer". I suspect this is from the recvfrom call within available. If I change this to use the IP of a remote machine as the remote address, poll properly times out and returns false after sendBytes.

To Reproduce

#include <iostream>
void DatagramSocketTest::testLocalIPIssue()
{
	DatagramSocket socket(SocketAddress("127.0.0.1", 0), true, true);

	socket.connect(SocketAddress("127.0.0.1", 2345));

	unsigned char values[5]{};
	socket.sendBytes(values, 5);

	Poco::Timespan timeout(5000);

	if (socket.poll(timeout, Socket::SELECT_READ))
	{
		std::cout << socket.available(); // -1 and last error is "connection reset by peer"
	}
}

Expected behavior
Poll returns false, just like it would when local and remote IPs don't match.

Please add relevant environment information:

  • Windows 10
  • POCO 1.12.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions