testing: drop SO_REUSEADDR from the port-availability probe#214
Merged
Conversation
PickAvailablePort()/PickAvailableEndpoint() probe a candidate port by binding to it, but the probe socket set SO_REUSEADDR before binding 0.0.0.0:port. On macOS/BSD that lets the probe succeed even while another process (e.g. a sibling test's server) already holds 127.0.0.1:port, falsely reporting the port as free. The caller then binds its real server to the same port and fails with EADDRINUSE. This only surfaces under parallel test execution, where multiple tests grab ports concurrently -- e.g. logging_test failing with "Cannot bind socket to [127.0.0.1:5136]. : Address already in use" when run alongside server_test/server_group_test/integration_test. An availability probe must observe the port exactly as a fresh server bind would, so it must not set SO_REUSEADDR. Without it, an occupied port is correctly rejected and PickAvailablePort() retries another random port. Verified with a deterministic repro (occupied 127.0.0.1:P; probe with SO_REUSEADDR reports free, without it reports occupied) and by stress-running the four port-grabbing rpc tests in parallel. Co-Authored-By: Claude Opus 4.8 <[email protected]>
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.
Problem
testing::PickAvailablePort()/PickAvailableEndpoint()probe a candidate port by binding to it. The probe setSO_REUSEADDRbefore binding0.0.0.0:port. On macOS/BSDSO_REUSEADDRlets that bind succeed even while another socket already holds127.0.0.1:port— so the probe reports an occupied port as free. The caller then binds its real server to the same port and fails:This only bites under parallel test execution, where sibling tests hold ports concurrently (observed on
logging_testrunning alongsideserver_test/server_group_test/integration_test). In isolation the test always passes.Fix
Drop
SO_REUSEADDRfrom the probe. An availability probe must observe the port exactly as a fresh server bind would; with the override it doesn't. Without it, an occupied port is correctly rejected andPickAvailablePort()just retries another random port (no functional loss).Verification
127.0.0.1:P(no reuse); probe0.0.0.0:PwithSO_REUSEADDRreports AVAILABLE (false positive), without it reports occupied (correct).🤖 Generated with Claude Code