Jim Crist-Harif <jiminy.cr...@gmail.com> added the comment:

> Is there an OS interface to ensure the same port on both stacks?

I don't think this is needed? Right now the code processes as:

- Expand host + port + family + flags into a list of one or more tuples of 
socket options 
(https://github.com/python/cpython/blob/401272e6e660445d6556d5cd4db88ed4267a50b3/Lib/asyncio/base_events.py#L1432-L1436)
- Iterate through this list, creating a new socket for each option tuple, and 
bind to the corresponding host + port 
(https://github.com/python/cpython/blob/401272e6e660445d6556d5cd4db88ed4267a50b3/Lib/asyncio/base_events.py#L1441-L1464)

In this case, each call to `socket.bind` gets a 0 port, thus binding to a new 
random open port number each time.

What I'm asking for is that if the user passes in `port=0`, then the port is 
extracted in the first call to `socket.bind` when looping and used for all 
subsequent `socket.bind` calls in the loop. This way we only ever choose a 
single random open port rather than 1 for each interface. FWIW, this is also 
what tornado does when `port=0` is provided.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue45693>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to