eventmachine/eventmachine — Issue #276: Connection#send_datagram() destroys the socket if there is no network route for the given IP
Author: ibc
Created: 2011-11-04 15:57:46+00:00
State: open

Scenario:

* Computer with no Internet access nor private network, but just 127.0.0.1.

* EventMachine opens an IPv4 UDP socket listening in 127.0.0.1:5060.

* The EM server tries to send a UDP datagram to 1.2.3.4:1234:

res = send_datagram("hello", "1.2.3.4", 1234)

* After that, 'res' is -1 and the UDP socket is destroyed (Connection#error? is true and 'netstat -putan' shows that the server is not listening in UDP 127.0.0.1:5060 anymore).

So this is critical in my scenario since, in the case the server when EM is running has not a default gateway (so just can send traffic to certain networks) a malicious user could make EM to send an UDP datagram to an IP for which the host has no route. It would make send_datagram() to return -1 and the UDP socket to be destroyed !

IMHO in the above case the UDP socket should not be destroyed. It's ok that send_datagram() returns -1 so I can check it and log some error in my application. But please, don't destroy the UDP socket when that occurs.