Skip to content

net: Listener.Addr reports port 0 after listening on port 0 #97

Open

Description

@0pcom

Listening on :0 asks the kernel for an ephemeral port, but the listener keeps the requested address, so ln.Addr() reports port 0. Binding an ephemeral port and then dialing ln.Addr() cannot work, which is the pattern httptest.NewServer uses.

The bound address needs to be read back from the socket after listen, through an optional interface so netdevs that cannot report it keep their current behavior. UDP is unaffected, because ListenUDP already fills in a port before binding.

PR #80 does that.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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