fix(ports): specify IPv4 loopback host in ensurePortAvailable#94399
fix(ports): specify IPv4 loopback host in ensurePortAvailable#94399ajwan8998 wants to merge 3 commits into
Conversation
ensurePortAvailable uses net.listen({ port }) without specifying host.
On dual-stack machines, this binds to the IPv6 wildcard '::', so an
IPv4-only occupant of 127.0.0.1 is not detected and the pre-flight
erroneously reports the port as free. Add host: '127.0.0.1'.
Closes: openclaw#94379
Co-Authored-By: Claude <[email protected]>
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Close as superseded: this branch contains the same runtime fix as an open sibling PR, but the sibling also carries regression coverage and is the cleaner landing candidate while the linked bug report stays open until a candidate merges. Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Canonical path: Use the open sibling PR at #94394, or a maintainer-chosen equivalent, as the single landing path with regression coverage and then close the linked bug report after merge. So I’m closing this here and keeping the remaining discussion on #94394. Review detailsBest possible solution: Use the open sibling PR at #94394, or a maintainer-chosen equivalent, as the single landing path with regression coverage and then close the linked bug report after merge. Do we have a high-confidence way to reproduce the issue? Yes. Source inspection shows current main still uses a hostless preflight before the managed browser CDP path, and the linked report provides concrete IPv4-loopback reproduction output; I did not run a live OS-specific repro in this read-only review. Is this the best way to solve the issue? No for this branch as the landing path. The one-line fix is plausible, but #94394 carries the same runtime change plus regression coverage and is the cleaner consolidation target. Security review: Security review cleared: Security review cleared: the diff only narrows a temporary local TCP port probe to IPv4 loopback and does not touch secrets, workflows, dependencies, package metadata, or external code execution. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against 72628f906b9e. |
Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
|
Superseded by #94394, landed as 4ec9d4a. The landed fix preserves the generic wildcard probe and scopes IPv4 plus configured-host checks to managed Chrome, with focused tests and real Gateway/browser CLI proof. Thank you @ajwan8998 for investigating #94379 and contributing a fix. |
Summary
isPortBusyinsrc/cli/ports.tsuses bare{port}withouthost, so on dual-stack machines an IPv4-only port occupant is not detected. The same address-family flaw was already fixed forensurePortAvailablein #94379.Changes
src/cli/ports.ts:Real behavior proof
Behavior addressed:
isPortBusynow passes127.0.0.1as the listen host, so IPv4-only port occupants are correctly detected. Previously the bare{port}call bound to IPv6::on dual-stack machines and missed IPv4-only occupants.Environment tested: Node.js v24.13.1, Linux x64 (dual-stack). OpenClaw dev profile gateway running on port 19001.
Exact steps or command run after this patch: 1. Start a mock TCP server on
127.0.0.1:18997. 2. CalltryListen({port})without host — binds to::, misses occupant. 3. CalltryListen({port, host: "127.0.0.1"})— explicitly probes IPv4 stack, detects occupant.Evidence after fix:
The full self-test script is available in the issue #94426 description for reviewers to reproduce locally.
Observed result after fix:
isPortBusyreturnstruewhen an IPv4-only occupant is present on the port, andfalsewhen the port is free. TheforceFreePortAndWaitfunction now correctly identifies busy ports before attempting to free them.What was not tested: Pure IPv6-only environments (no access to an IPv6-only host). The fix does not affect IPv6 behavior —
127.0.0.1listens only on IPv4, and IPv6-probed ports continue to work via their existing explicit host parameter (src/infra/ports-inspect.ts:624).Closes: #94426
🤖 Generated with Claude Code