Skip to content

Why does _pick_unused_port_without_server() try random ports instead of letting the OS choose? #16

@dragonsinth

Description

@dragonsinth

Upgrading to the latest Go AppEngine runtime (which has an embedded copy of this code) put us into a code path that uses port_picker to select an open port number, which is then passed off to the Go subprocess to bind. Since the upgrade, we've seen a large number of both CI failures and local dev failures stemming from the Go process being unable to bind the port that the python code is asking it to bind.

Digging into the portpicker code, I'm curious why it tries random ports in the 15000-25000 range rather than just letting the OS pick a free port? My understanding is that letting the OS assign a free port would interoperate better with other (non-Python) processes random binding port 0, since the OS will try to ensure that successive port 0 binds don't conflict with each other.

Metadata

Metadata

Assignees

No one assigned

    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