Skip to content

Fix get_available_port #536

@sharpener6

Description

@sharpener6

For both zmq and ymq, if user didn't specify the port, then port should be 0, and we should let OS to bind with available port, then return it

current behavior is we use get_available_tcp_port, then use this port to actually listen:

def get_available_tcp_port(hostname: str = "127.0.0.1") -> int:
    with socket.socket(socket.AddressFamily.AF_INET, socket.SocketKind.SOCK_STREAM) as sock:
        sock.bind((hostname, 0))
        return sock.getsockname()[1]

But there is a gap between we get_available_tcp_port and then use it, in this gap, other program might use the port, and it's not consistent. we should bind it when create zmq/ymq connection and return the port number

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions