Message345209
When using loop.create_datagram_endpoint(), the default for reuse_address=True, which sets the SO_REUSEADDR sockopt for the UDP socket.
This is a dangerous and unreasonable default for UDP, because in Linux it allows multiple processes to create listening sockets for the same UDP port and the kernel will randomly give incoming packets to these processes.
I discovered this by accidentally starting two Python asyncio programs with the same UDP port and instead of getting an exception that the address is already in use, everything looked to be working except half my packets went to the wrong process.
The documentation also refers to behavior with TCP sockets:
https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.create_datagram_endpoint
"reuse_address tells the kernel to reuse a local socket in TIME_WAIT state, without waiting for its natural timeout to expire. If not specified will automatically be set to True on Unix."
This is true for TCP but not UDP.
Either the documentation should reflect the current (dangerous) behavior or the behavior should be changed for UDP sockets.
Workaround is of course to create your own socket without SO_REUSEADDR and pass it to create_datagram_endpoint(). |
|
Date |
User |
Action |
Args |
2019-06-11 09:36:54 | vaizki | set | recipients:
+ vaizki, asvetlov, yselivanov |
2019-06-11 09:36:54 | vaizki | set | messageid: <1560245814.37.0.496048869185.issue37228@roundup.psfhosted.org> |
2019-06-11 09:36:54 | vaizki | link | issue37228 messages |
2019-06-11 09:36:54 | vaizki | create | |
|