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, jcristharif, yselivanov
Date 2021-11-02.18:32:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1635877955.05.0.115164279782.issue45693@roundup.psfhosted.org>
In-reply-to
Content
To create a new server with `loop.create_server` that listens on all interfaces and a random port, I'd expect passing in `host=""`, `port=0` to work (per the documentation). However, as written this results in 2 different ports being used - one for ipv4 and one for ipv6. Instead I'd expect a single random port be determined once, and reused for all other interfaces.

Running the example test code (attached) results in:

```
$ python test.py
listening on 0.0.0.0:38023
listening on :::40899
Traceback (most recent call last):
  File "/home/jcristharif/Code/distributed/test.py", line 36, in <module>
    asyncio.run(main())
  File "/home/jcristharif/miniconda3/envs/dask/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/home/jcristharif/miniconda3/envs/dask/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/home/jcristharif/Code/distributed/test.py", line 30, in main
    assert len(ports) == 1, "Only 1 port expected!"
AssertionError: Only 1 port expected!
```

This behavior can be worked around by manually handling `port=0` outside of asyncio, but as it stands naive use can result in accidentally listening on multiple ports.
History
Date User Action Args
2021-11-02 18:32:35jcristharifsetrecipients: + jcristharif, asvetlov, yselivanov
2021-11-02 18:32:35jcristharifsetmessageid: <1635877955.05.0.115164279782.issue45693@roundup.psfhosted.org>
2021-11-02 18:32:35jcristhariflinkissue45693 messages
2021-11-02 18:32:34jcristharifcreate