Skip to content

fix(cli): add IPv4 loopback host to isPortBusy#94448

Closed
ajwan8998 wants to merge 23 commits into
openclaw:mainfrom
ajwan8998:fix/issue-94426-isportbusy-ipv4
Closed

fix(cli): add IPv4 loopback host to isPortBusy#94448
ajwan8998 wants to merge 23 commits into
openclaw:mainfrom
ajwan8998:fix/issue-94426-isportbusy-ipv4

Conversation

@ajwan8998

@ajwan8998 ajwan8998 commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Closes #94426

What Problem This Solves

isPortBusy() used a host-less probe (IPv6-first default) which missed IPv4-only port occupants on dual-stack hosts. Port detection returned free for an occupied port when the listener was IPv4-only.

Why This Change Was Made

Changed isPortBusy to use checkPortInUse from ports-inspect.ts which probes with explicit host resolution, correctly detecting IPv4-only occupants.

Evidence

$ npx tsx -e 'import { createServer } from "node:net"; import { checkPortInUse } from "./src/infra/ports-inspect.ts"; ...'

checkPortInUse result:
busy

An IPv4-only listener on port 19876 is correctly detected as busy by checkPortInUse.

Same address-family flaw as openclaw#94379: isPortBusy uses bare {port}
without specifying host, missing IPv4-only port occupants.

Closes: openclaw#94426
Co-Authored-By: Claude <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: XS triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 18, 2026
ajwan8998 and others added 2 commits June 18, 2026 16:23
Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
@ajwan8998

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close as superseded: #94949 is the cleaner open landing path for the same isPortBusy IPv4-only listener bug, while this branch is conflicting and still collapses inconclusive probes into a false not-busy result.

Root-cause cluster
Relationship: superseded
Canonical: #94949
Summary: This PR and the related candidates all address the same isPortBusy IPv4-only listener preflight bug; the viable canonical landing path is now the open clean replacement PR with proof and unknown-state handling.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Canonical path: Land #94949 as the canonical fix, then close the linked issue and duplicate PR candidates after merge.

So I’m closing this here and keeping the remaining discussion on #94949.

Review details

Best possible solution:

Land #94949 as the canonical fix, then close the linked issue and duplicate PR candidates after merge.

Do we have a high-confidence way to reproduce the issue?

Yes. Source inspection shows current main still uses a hostless isPortBusy bind and forceFreePortAndWait exits early when it reports false; I did not run the full gateway --force live path in this read-only review.

Is this the best way to solve the issue?

No. Reusing a multi-address probe is the right direction, but this branch loses the unknown state and is superseded by the clean, proof-positive #94949 path.

Security review:

Security review cleared: The diff only changes local TypeScript port-probe control flow and exports an existing helper; it adds no dependency, workflow, secret, permission, or supply-chain surface.

AGENTS.md: found and applied where relevant.

What I checked:

  • Current force path still depends on isPortBusy: Current main still has isPortBusy perform a hostless tryListenOnPort({ port, exclusive: true }), and forceFreePortAndWait returns before listener lookup when that helper returns false. (src/cli/ports.ts:133, fcedd37067ec)
  • Current shared probe already has the four-host status contract: probePortUsage probes 127.0.0.1, 0.0.0.0, ::1, and ::, and preserves an unknown status when probes are inconclusive. (src/infra/ports-probe.ts:52, fcedd37067ec)
  • This PR loses the inconclusive state: At this PR head, isPortBusy returns status === "busy", so unknown from the probe is treated the same as free. (src/cli/ports.ts:134, 72ac98190f72)
  • This PR is not a viable landing branch: Live GitHub state reports this branch as CONFLICTING / DIRTY, with status: 📣 needs proof still present. (72ac98190f72)
  • Canonical replacement PR is open and viable: Live GitHub state for fix(ports): route isPortBusy through checkPortInUse to catch IPv4-only occupants #94949 is MERGEABLE / CLEAN, with proof: sufficient and status: 👀 ready for maintainer look; exact-head checks were success/skipped/neutral with no failures in the queried rollup. (61af76063bf5)
  • Canonical replacement preserves unknown as not-free: The replacement PR uses the current probePortUsage helper and returns true for any status other than confirmed free, preserving conservative force-cleanup behavior. (src/cli/ports.ts:139, 61af76063bf5)

Likely related people:

  • steipete: History shows Peter Steinberger added the retrying --force port cleanup helper and later hardened its lsof/fuser behavior in the central CLI port files. (role: introduced and hardened gateway force-port behavior; confidence: high; commits: 0b4e70e38b92, 39f7dbfe02ce; files: src/cli/ports.ts, src/cli/program.force.test.ts)
  • vincentkoc: Current blame is carried through a recent Vincent Koc commit, and the viable replacement PR contains Vincent Koc's commit reusing the canonical probePortUsage helper. (role: recent area contributor and canonical replacement refactor author; confidence: medium; commits: 3f2b205dde19, 928816acbf68; files: src/cli/ports.ts, src/cli/program.force.test.ts, src/infra/ports-inspect.ts)
  • huangjianxiong: Authored the merged adjacent address-family fix for managed Chrome port preflight, which shares the same multi-address probing invariant on a different surface. (role: adjacent sibling-fix author; confidence: medium; commits: 4ec9d4a2b511; files: src/infra/ports.ts, src/infra/ports.test.ts, extensions/browser/src/browser/chrome.ts)

Codex review notes: model internal, reasoning high; reviewed against fcedd37067ec.

@clawsweeper clawsweeper Bot added the rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. label Jun 18, 2026
@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jun 18, 2026
…PortBusy

Export checkPortInUse from ports-inspect.ts and reuse it in isPortBusy
instead of hard-coding host: "127.0.0.1". checkPortInUse already
iterates over all hosts (127.0.0.1, 0.0.0.0, ::1, ::), providing a
more complete port-busy check that handles both IPv4-only and
IPv6-only occupants.

Closes: openclaw#94426
@ajwan8998

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@ajwan8998

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper could not start a re-review for this item.

Reason: re-review requires an open issue or PR.

@ajwan8998

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

2 similar comments
@ajwan8998

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@ajwan8998

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

@clawsweeper clawsweeper Bot closed this Jun 23, 2026
@ajwan8998

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

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

Labels

cli CLI command changes merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

isPortBusy preflight misses IPv4-only occupant (same address-family flaw as #94379)

1 participant