fix(web): check and bind free ports on the same host - #527
Merged
Merged
Conversation
findPorts() checked candidate ports on 127.0.0.1 while the express server and BrowserSync bound the wildcard address, so a port reported as free could fail with EADDRINUSE on listen() (seen on Windows when starting a second styleguide). Add a `web.server.host` option and use it for the port check, the express listen(), BrowserSync's `listen` and the generated URLs. When unset, getPort checks every local address and the server binds the wildcard address as before. Co-Authored-By: Claude Opus 5.5 (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
Alternative to #523. The port check and the bind now use the same address, and that address is set by a new
web.server.hostoption.hostunset (default): get-port checks every local address and the server binds the wildcard address. Default behaviour matches fix(web): check free ports on all addresses, not only 127.0.0.1 #523, which fixes the EADDRINUSE when styleguides start in parallel.hostset, e.g.'127.0.0.1': the port check and both binds use that address only. The dev server isn't reachable from the LAN.Explicitly configured ports (
web.server.port) are still not checked. If one is taken,listen()fails with EADDRINUSE. Checking would make get-port fall back to a random port without any error.Evidence
Before: a new test run against
main'sserver.js. The configured host is ignored and the server binds the wildcard address:After:
Tests 4 passed (4)inpackages/web/test/server.spec.js.Manual check with BrowserSync (
sync: true), usingss -ltn:Tested on Windows by starting two styleguides in parallel. Both start on their own ports, with no EADDRINUSE.
Merge Danger
Door: two-way
The new option is additive and defaults to
null. Reverting it only removes the option.Blast Radius: dev-server
Only
fractal start/fractal-servegoes throughfindPorts, so the build path is unaffected. Withhostunset, the port check is stricter than before: a port has to be free on every address, not only on127.0.0.1. The first port picked can therefore move up a slot if another process holds it on a different interface. Anyone who setssyncOptions.listendirectly still overrides the configured host for BrowserSync.🤖 Generated with Claude Code