This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jcristharif
Recipients asvetlov, eric.smith, jcristharif, yselivanov
Date 2021-11-02.20:24:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1635884647.29.0.980129463667.issue45693@roundup.psfhosted.org>
In-reply-to
Content
> 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.
History
Date User Action Args
2021-11-02 20:24:07jcristharifsetrecipients: + jcristharif, eric.smith, asvetlov, yselivanov
2021-11-02 20:24:07jcristharifsetmessageid: <1635884647.29.0.980129463667.issue45693@roundup.psfhosted.org>
2021-11-02 20:24:07jcristhariflinkissue45693 messages
2021-11-02 20:24:07jcristharifcreate