fix(browse): resolve findPort() race condition in Node.js polyfill#490
Open
evb87-tech wants to merge 1 commit intogarrytan:mainfrom
Open
fix(browse): resolve findPort() race condition in Node.js polyfill#490evb87-tech wants to merge 1 commit intogarrytan:mainfrom
evb87-tech wants to merge 1 commit intogarrytan:mainfrom
Conversation
On Windows, findPort() tests port availability by calling Bun.serve() then immediately testServer.stop(). In real Bun this is synchronous, but the Node.js polyfill wraps http.createServer() + server.listen() which are async. Neither bind nor close completes before findPort() returns, causing EADDRINUSE 100% of the time when the real server tries to bind. Replace Bun.serve() port probing with net.createServer() using proper async bind/close via Promise. This works identically on both Bun (where net is available) and Node.js, eliminating the race condition. Fixes garrytan#486 Signed-off-by: Eric Van Boxsom <14831976+evb87-tech@users.noreply.github.com>
ec879a8 to
1d4b1ad
Compare
garrytan
added a commit
that referenced
this pull request
Mar 27, 2026
Replaces Bun.serve() port probing with net.createServer() for proper async bind/close semantics. Fixes Windows EADDRINUSE race condition. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
3 tasks
garrytan
added a commit
that referenced
this pull request
Mar 27, 2026
…odex fallback, Windows fix, Python patterns (v0.12.9.0) (#561) * fix: sync package.json version with VERSION file (0.12.7.0) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * perf: shallow clone for faster install (#484) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: Python/async/SSRF patterns in review checklist (#531) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: namespace skill symlinks with gstack- prefix (#503) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: add uninstall script (#323) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: office-hours Claude subagent fallback when Codex unavailable (#464) Updates generateCodexSecondOpinion resolver to always offer second opinion and fall back to Claude subagent when Codex is unavailable or errors. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: findPort() race condition via net.createServer (#490) Replaces Bun.serve() port probing with net.createServer() for proper async bind/close semantics. Fixes Windows EADDRINUSE race condition. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * test: add tests for uninstall, setup prefix, and resolver fallback - Uninstall integration tests: syntax, flags, mock install layout, upgrade path - Setup prefix tests: gstack-* prefixing, --no-prefix, cleanup migration - Resolver tests: Claude subagent fallback in generated SKILL.md Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * chore: bump version and changelog (v0.12.9.0) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
rapidstartup
pushed a commit
to rapidstartup/gstack
that referenced
this pull request
Mar 29, 2026
…odex fallback, Windows fix, Python patterns (v0.12.9.0) (garrytan#561) * fix: sync package.json version with VERSION file (0.12.7.0) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * perf: shallow clone for faster install (garrytan#484) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: Python/async/SSRF patterns in review checklist (garrytan#531) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: namespace skill symlinks with gstack- prefix (garrytan#503) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: add uninstall script (garrytan#323) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: office-hours Claude subagent fallback when Codex unavailable (garrytan#464) Updates generateCodexSecondOpinion resolver to always offer second opinion and fall back to Claude subagent when Codex is unavailable or errors. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: findPort() race condition via net.createServer (garrytan#490) Replaces Bun.serve() port probing with net.createServer() for proper async bind/close semantics. Fixes Windows EADDRINUSE race condition. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * test: add tests for uninstall, setup prefix, and resolver fallback - Uninstall integration tests: syntax, flags, mock install layout, upgrade path - Setup prefix tests: gstack-* prefixing, --no-prefix, cleanup migration - Resolver tests: Claude subagent fallback in generated SKILL.md Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * chore: bump version and changelog (v0.12.9.0) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
3 tasks
24601
pushed a commit
to 24601/gastack
that referenced
this pull request
Mar 29, 2026
Replaces Bun.serve() port probing with net.createServer() for proper async bind/close semantics. Fixes Windows EADDRINUSE race condition. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
Bun.serve()port probing infindPort()withnet.createServer()using proper async bind/closelisten()/close()creates a race conditionFixes #486
Problem
findPort()tests port availability by callingBun.serve({ port })thentestServer.stop(). In real Bun, both are synchronous. In the Node.js polyfill (Windows), they wraphttp.createServer()+server.listen()/server.close()— both async. Neither completes beforefindPort()returns:Root cause: the polyfill's
stop()returnsundefined(fire-and-forget), not a Promise — callers cannot await socket teardown.Fix
New
isPortAvailable()helper usingnet.createServer()with Promise-based bind/close:This properly awaits both bind AND close before returning. Works on both Bun (where
netis available) and Node.js.Changes
browse/src/server.ts: +18/-10 linesimport * as net from 'net'isPortAvailable()helperBun.serve()port probes infindPort()withawait isPortAvailable(port)browse/test/findport.test.ts: 6 new tests (all passing)Test results
Tests verify:
isPortAvailablereturns true for free portsisPortAvailablereturns false for occupied portsisPortAvailablereturns (no leaked sockets)stop()is fire-and-forget (documents root cause)net.createServerapproach releases ports cleanly (proves fix)bun-polyfill.test.tspasses (4/4, no regression)browse/test/suite: 147/151 pass (4 pre-existing failures from missingplaywright/diffpackages)