Open WaelKarkoub opened 2 years ago
I think this is a bug in libzmq, unless I'm mistaken. When you bind to a random port, it's really doing:
s.bind('tcp://127.0.0.1:*')
url = s.last_endpoint
# tcp://127.0.0.1:12345
and parsing the port out of the LAST_ENDPOINT property. However, when you access LAST_ENDPOINT after a udp bind, it doesn't return the resolved port:
In [23]: s.bind('tcp://127.0.0.1:*');
In [24]: s.last_endpoint
Out[24]: b'tcp://127.0.0.1:55021'
In [25]: s.bind('udp://127.0.0.1:*');
In [26]: s.last_endpoint
Out[26]: b'127.0.0.1:*'
I don't know if this is on purpose, but it means bind_to_random_port
's default behavior can't work until libzmq fixes that.
If you specify an explicit port range, pyzmq has to use its own logic to pick a random port (which can require retries, as it picks a port before trying to bind), in which case it works:
In [27]: s.bind_to_random_port('udp://*', min_port=10101, max_port=12345)
Out[27]: 10611
I'm new to pyzmq but I believe I found a bug with
bind_to_random_port
. I ran this script to install zmq and pyzmqthen trying to run
some_socket.bind_to_random_port("udp://*")
I get the following errorline 411 in
sugar/socket.py
,url = cast(bytes, self.last_endpoint).decode('ascii', 'replace')
, i'm gettingurl = *:*
.Let me know if there's a way I can contribute to this bug.