Repository navigation
tcp: release the port of a wildcard-bound endpoint when it is closed - #16989
Merged
Merged
Conversation
A wildcard-bound endpoint reserves a port using the wildcard address, but connecting replaces its local address with the connected address A dual-stack endpoint also changes its effective network protocols when connecting to an IPv4-mapped peer, leaving an IPv6 reservation that cleanup did not release Track the address and network protocols of the reservation independently from the connected endpoint and retain the remaining IPv6 ownership after releasing the IPv4 reservation Verify IPv4 and IPv4-mapped wildcard binds with a Linux and gVisor syscall test and add a bind/close benchmark Fixes #16102
copybara-service
Bot
force-pushed
the
test/cl1013927052
branch
2 times, most recently
from
November 5, 2026 02:20
6014fca to
ab77718
Compare
…ease PiperOrigin-RevId: 1014324338
copybara-service
Bot
force-pushed
the
test/cl1013927052
branch
from
November 5, 2026 03:26
ab77718 to
e349665
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
tcp: release the port of a wildcard-bound endpoint when it is closed
Fixes #16102
Compatibility
COMPATIBILITY:NEW-APP-CONFIG— fixes source-port exhaustion in the repeated wildcard-bound connections used by the BusyBoxnchealthchecks reported in #16102Problem and fix
A wildcard bind reserves its port using the wildcard address, but connecting replaces the endpoint local address with the connected address
A dual-stack wildcard bind also reserves both IPv6 and IPv4, while connecting to an IPv4-mapped peer changes
effectiveNetProtosto IPv4 and releases the IPv4 reservationCleanup must therefore use the reservation address and the network protocols still owned by the endpoint, rather than the connected address and effective protocols
boundAddrandboundNetProtosfor explicit binds, implicit connect reservations and accepted tupleschecklocksannotations on the new fieldsRebased onto
0bbcbf9de7626fcecba97f37723dce80b435d73dRegression coverage
Adapted the syscall test suggested by @tamird into
SocketInetLoopback.WildcardBoundPortReleasedOnClose, covering IPv4 wildcard and dual-stack wildcard connections to an IPv4 peerThe test uses an abortive close to avoid TIME_WAIT and verifies that both IPv4 and IPv6-only wildcard binds can reuse the port
The review reproducer passes on Linux and fails on the previous PR implementation with
EADDRINUSEfor the IPv6-only bindThe updated test passes on both Linux and gVisor, replacing the duplicate Go behavior test
Local validation
Linux ARM64 in a Colima-backed Ubuntu container, Bazel 8.8.1
socket_inet_loopbacksuite on native Linux and gVisor systrap — passed, 8 shards eachmake lint— passedmake lint-cc— passed with the compilation database scoped to the affected syscall target and its 16 source filesgit diff --check— passedPerformance
Added
BenchmarkWildcardBindCloseand compared the master base against this change with the same benchmark and build flagsAlternating before/after execution order, 32 samples per version, Linux ARM64 with 6 vCPUs
The benchmark measures a small bind/close overhead, with no additional allocations
Each sample runs the built test binary with
-test.run='^$' -test.bench='^BenchmarkWildcardBindClose$' -test.benchmem -test.count=1, followed bybenchstatcomparisonThese are local results, not a claim that GitHub CI has passed
Auto-fixed-by: [🤖] @EtiennePerot
FUTURE_COPYBARA_INTEGRATE_REVIEW=#16180 from akasakariko:fix-wildcard-bind-port-release 48e209b