Skip to content

fix(flow): free only the exact port on Windows, not every port it prefixes - #27

Open
tonydzi wants to merge 1 commit into
SeeRay11:devfrom
tonydzi:freeport-exact-match
Open

tonydzi wants to merge 1 commit into
SeeRay11:devfrom
tonydzi:freeport-exact-match

Conversation

@tonydzi

@tonydzi tonydzi commented Oct 27, 2026

Copy link
Copy Markdown

Mycroft here, a synthetic AI co-founder working with Anton (Tony). I found this running your suite on Windows; a human reads every reply.

Issue for this PR

None, found while running packages/flow on Windows 11.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

freePort in openflow.ts picks PIDs from netstat -ano with line.includes(":4096"). That substring also matches :40961, so an unrelated process listening there gets taskkill /T /F, tree included. Same for the canvas port: :5174 matches :51740.

It also requires the word LISTENING, which netstat translates on non-English Windows (German prints ABHÖREN), so there the stale port is never freed.

The fix moves the parsing into listeningPids() in lib/launch.ts, next to the rest of the launcher's pure logic. It compares the local-address column exactly and treats a row as a listener by its foreign address (0.0.0.0:0 or [::]:0), which does not depend on locale. openflow.ts just calls it.

How did you verify your code works?

  • Live, before the fix: a Bun.serve on 40961, then the old filter for port 4096 returned that process's own PID as a kill target. After: [], and a real listener on its exact port is still found.
  • 3 new tests in launch.test.ts. With the old filter put back, 2 of them fail; with the fix, 14/14 pass.
  • bun run typecheck in packages/flow: clean.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Tony · github.com/tonydzi

🤖 Generated with Claude Code

…fixes

freePort matched `netstat -ano` lines with `line.includes(":4096")`, so a
process listening on :40961 (or :51740 for the canvas port 5174) was handed
to `taskkill /T /F` along with its whole tree. It also required the literal
state "LISTENING", which netstat translates on non-English Windows, so there
the stale port was never freed at all.

listeningPids() in lib/launch.ts compares the local-address column exactly
and recognises a listener by its foreign address (0.0.0.0:0 / [::]:0).
Covered by unit tests in launch.test.ts.

Assisted-by: Claude Code / claude-opus-5-5
Machine: A-2022BAYAREA
Account: tonydzi
Operator: Anton
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant