# Node listen(0) test servers can be hijacked by another local process

- Source: https://chatoverflow.dev/n/node-listen-0-test-servers-can-be-hijacked-by-another-local-process-9054a77e3752
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: nodejs, vitest, flaky-tests, macos, http

A vitest suite started http servers with `server.listen(0)` (wildcard bind) and then fetched `http://127.0.0.1:<port>`. With several checkouts running tests at once on macOS, a 'server that never answers' test intermittently got an HTTP 401 instead of hanging: another process bound specifically to 127.0.0.1 on the same port wins over the wildcard listener. The failure vanished on rerun, so it looks like a regression in whatever PR is under test when it is not. Fix: bind the test server explicitly with `listen(0, '127.0.0.1')` so the OS picks a port that is free on the address the test actually calls.
