Repository navigation
fix(dev): enumerate and free held ports on Windows - #643
Draft
invisibletype wants to merge 1 commit into
Draft
invisibletype wants to merge 1 commit into
invisibletype wants to merge 1 commit into
Conversation
PR CoreBunch#170 stopped `bun run dev` / `bun run start` from crashing on Windows by having the port preflight return no holders there. But that means a held port can't be reclaimed: an orphaned dev server (common after an unclean shutdown) never frees the socket, so the preflight waits ~30s and then exits with an error the user can't act on. Implement real holder lookup on Windows via `netstat -ano` + `tasklist`, so `ensurePortFree` identifies the holding process and offers to kill it and take over — the same experience the Unix `lsof`/`ps` path gives. Replace the Unix-only `sleep` subprocess in the kill/re-probe loops with the portable `Bun.sleepSync`, and drop the Windows wait-and-give-up fallback this supersedes. No behavior change on macOS/Linux. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
invisibletype
force-pushed
the
fix/windows-port-preflight
branch
from
October 14, 2026 15:48
cd60566 to
e32e33e
Compare
This branch has not been deployed
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.
Summary
Builds on #170. That PR stopped
bun run dev/bun run startfrom crashing on Windows — the port preflight shelled out tolsof, which doesn't exist there — by returning no holders on Windows and waiting ~30s in case a previous dev server is shutting down. But an orphaned dev server never frees the socket, so that path just waits and then exits with a (Unix-only) error the user can't act on.This implements real holder lookup on Windows via
netstat -ano+tasklist, soensurePortFreeidentifies the process holding the port and offers to kill it and take over — the same experience the Unixlsof/pspath already gives. It also:sleepsubprocess in the kill / re-probe loops with the portableBun.sleepSync,netstat … | findstron Windows), andNo behavior change on macOS/Linux. Rebased onto current
main(includes #170).Verification
bun run build— passed (tsc -b && vite build), afterbun installpicked up the newyjs/lib0deps frommainbun test— runs in CI on this PR;freePort.tsis a standalone dev script imported only byscripts/dev.ts/scripts/start.ts, outside the tested module graph, so it can't affect suite resultsbun run lint— passednetstat/tasklistparsing correctly identified the PIDs + names holding:5174and:3001, and returned empty for a free portChecklist
🤖 Generated with Claude Code