Skip to content

feat(client): set IP_BIND_ADDRESS_NO_PORT before binding a local address - #355

Open
basundhara-c wants to merge 1 commit into
hyperium:masterfrom
basundhara-c:bind-address-no-port
Open

basundhara-c wants to merge 1 commit into
hyperium:masterfrom
basundhara-c:bind-address-no-port

Conversation

@basundhara-c

@basundhara-c basundhara-c commented Nov 25, 2026 •

Copy link
Copy Markdown

When HttpConnector has a local address set, bind_local_address binds ip:0 before connect. Linux then picks the source port at bind time without knowing the destination, so every socket from that local IP takes a port from the same ephemeral range. A client that opens many connections from one bound address to many different destinations fails with EADDRNOTAVAIL once the range is used up, even though each destination only has a few connections.

This sets IP_BIND_ADDRESS_NO_PORT on Linux and Android before that bind. The kernel then picks the port at connect, where it only needs to be unique per destination, so the same local port can be reused toward different destinations. If the option can't be set, it logs a warning and binds as before.

Envoy does the same for upstream connections with a bound source address (envoyproxy/envoy#45916).

Added local_address_sets_bind_address_no_port, which connects with and without a local address and reads the option back off the socket.

Signed-off-by: Basundhara Chakrabarty <basundhara17061996@gmail.com>
@basundhara-c
basundhara-c marked this pull request as ready for review November 25, 2026 07:31

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant