Repository navigation
fix(test): prevent port probes from colliding with fixture reservations - #155228
Conversation
Make numeric allocation probes acquire the same exclusive port claims as persistent test fixtures. Retain claims until probe sockets close so a competing probe cannot occupy a port during fixture reservation or handoff. Add a deterministic two-fixture regression that fails with EADDRINUSE on the previous owner and passes after the repair. Preserve existing port ranges, derived-port ownership, cleanup, and zero-retry claim behavior. Related: #150642. Investigated from run 35649415771, job 106498397182 on #153314's unrelated merge ref. No product runtime or update behavior changes.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 21, 2026, 6:05 PM ET / 22:05 UTC. ClawSweeper reviewWhat this changesMakes test port probes share exclusive claims with fixture reservations and adds a deterministic overlapping-allocation regression. Merge readiness✅ Ready for maintainer review The fix remains necessary: current main still allows allocation probes to bypass fixture claims. The patch addresses that race without changing product runtime behavior, and no blocking defect was found. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw’s test port allocator selects local ports for isolated server fixtures. Temporary socket probes and persistent fixture reservations now coordinate through the same file-lock owner. flowchart TD
A[Test requests port block] --> B[Select candidate ports]
B --> C[Acquire exclusive claims]
C -->|Already claimed| B
C --> D[Probe local sockets]
D --> E[Close probes and release claims]
E --> F[Fixture claims and reserves ports]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceTests +97. Total +97 across 4 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep probe and fixture exclusion under one claim owner, with socket closure preceding claim release and deterministic coverage of overlapping acquisitions. Do we have a high-confidence way to reproduce the issue? Yes: source establishes the unclaimed-probe window, and the supplied regression deterministically overlaps that probe with fixture acquisition. The PR reports a before/after failure and pass; this review did not execute it. Is this the best way to solve the issue? Yes: extending the existing exclusive claim owner closes the race without adding retries, timeouts, or a competing reservation mechanism. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 1fab25b37f95. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
Compose initial TCP and HTTP reservations over the canonical claim owner extracted in #155228, retaining its claim-aware allocation probes. Retry only an automatic initial bind that reports EADDRINUSE after joined rollback; keep explicit and published ports, later reacquisition, cancellation and cleanup failures pinned to their existing contracts. Integrate #155209 without replacing its published ancestry. Current-main controls reproduce both real initial-bind failures. The composed candidate passes all 123 cases across seven files and all 34 selected checks, including 25 core-test type graphs. Fresh P2 review has no actionable findings. The recorded #155098 group passed once on the available 4-CPU Testbox with its normal two-worker fallback. That result does not reproduce the original eight-worker topology or establish the historical competing socket owner; earlier zero-close acquisition failures also remain unattributed.
…ns (openclaw#155228) Make numeric allocation probes acquire the same exclusive port claims as persistent test fixtures. Retain claims until probe sockets close so a competing probe cannot occupy a port during fixture reservation or handoff. Add a deterministic two-fixture regression that fails with EADDRINUSE on the previous owner and passes after the repair. Preserve existing port ranges, derived-port ownership, cleanup, and zero-retry claim behavior. Related: openclaw#150642. Investigated from run 35649415771, job 106498397182 on openclaw#153314's unrelated merge ref. No product runtime or update behavior changes.
What Problem This Solves
Fixes an
EADDRINUSErace between a test fixture's idle reservation and another allocator's temporary port probe. Investigated after run 35649415771, job 106498397182 failed the final config/environment case inopenclaw-test-instance.test.tson #153314's unrelated merge ref.Related: #150642, which fixed listener handoff in the separate in-process metadata-close fixture.
User Impact
No product runtime or update behavior changes. Test fixtures keep their existing isolated state, Linux non-ephemeral port ranges, derived-port claims, and cleanup contracts. No new configuration, CLI options, dependencies, schemas, retries, or timeouts.
Why This Change Was Made
Numeric-port probes were binding sockets before acquiring the fixture's logical claim. A competing probe could occupy the selected port while its eventual fixture owner tried to reserve it. Both allocation probes and persistent fixture reservations now use the existing exclusive claim owner, with probe claims released after the sockets close. The shared low-level claim operation is factored out to avoid a dependency cycle.
The deterministic regression overlaps two real fixture acquisitions in one worker using independent allocator module copies and event gates. It fails before the repair with
EADDRINUSE; the repaired acquisitions both return distinct live reservations. The reproduced second binder isprobeTestPortinsrc/test-utils/ports.ts(pre-fix line 65). The archived job did not record bind PIDs, so the precise historical holder of port 21336 remains unproven.Evidence
EADDRINUSEin 42 ms; final candidate passes in 35 ms. Bind trace identifies the live contender atsrc/test-utils/ports.ts:65on the pre-fix source (PID 5230, worker thread 1, port 15024).--maxWorkers=1: Linux 17.26 s Vitest wall (93% transform), 35 ms test time; macOS 9.58 s wrapper wall, 47 ms test time.node scripts/check-changed.mjs -- test/helpers/openclaw-test-instance.port-collision.test.tsselection passed. Unchanged support-code proof was reused.Final remote proof: Blacksmith Testbox
tbx_01m32ym03htyd1qcxgsh000yjx, lease workflow, wrapper exit 0. Earlier unchanged-support proof usedtbx_01m32vp352efzn7ds32feh1x25, lease workflow. Both used isolated test state and owned listeners. Hosted PR CI timing is pending.Runtime LOC +0/−0; shared test support +94/−73; regression +76/−0.