fix(web): check free ports on all addresses, not only 127.0.0.1 - #523
frankl7800 wants to merge 5 commits into
Conversation
- add .project to .gitignore
- drop host option from getPort calls in findPorts - express and BrowserSync bind the wildcard address, so a loopback- only check could report ports as free that are taken on 0.0.0.0 - on Windows the subsequent listen() then failed with EADDRINUSE - without a host, get-port checks every local interface, matching the set of addresses the server actually binds
- add .classpath, .project and .settings to gitignore - they are IDE-generated and differ per workstation
|
Thanks for tracking this down. The diagnosis is spot on: the port check on I'd rather not drop The |
|
Closing as #527 fixed this without removal of host option. |
Problem
Starting a second styleguide while another one is running fails:
The port had just been reported as free.
Cause
findPorts()checked candidate ports at a single address while the server occupies all of them:BrowserSync gets the sync port without a host as well, so it binds just as broadly. The check was the narrowest possible, the bind the widest.
On Windows a process may bind
127.0.0.1:3001while another one holds0.0.0.0:3001— the two only collide once the wildcard bind happens. On Linux and macOS the loopback bind already conflicts, which is why this surfaced on Windows.Change
Drop the
hostoption.get-porthas two modes:Without
hostit testsundefined(Node's default bind),0.0.0.0and every interface address — exactly the set the server can occupy. Check and bind agree again.const ipexisted only for those four call sites and goes with them.The check gets stricter, not looser: a port is only handed out when it is free everywhere, which is what the wildcard bind needs. No port that used to work becomes unavailable.
findPortshas a single caller,server.start(), so this only affects dev servers — the build path never touches it.Testing
Linked the fix into DHPol, Coburg and Wuppertal and started all three styleguides in turn with
yarn start(pnpm startfor Coburg). Each one picked its own port triplet and stayed up; no EADDRINUSE.DHPol
Coburg
Wuppertal
Note for the release
Downstream styleguides that serve through
fractal-servecannot start in parallel until this ships, so this needs a@fractality/webrelease and a bump in@fractality/fractality.