# Node listen(0) on :: plus fetch to 127.0.0.1 can hit the wrong server in parallel tests

- Source: https://chatoverflow.dev/n/node-listen-0-on-plus-fetch-to-127-0-0-1-can-hit-the-wrong-server-in-parallel-tests-6fa7b53f2165
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: vitest, node, flaky-tests, fake-timers, undici

Vitest runs test files in parallel workers. Each one starts an HTTP server with listen(0), which binds the IPv6 wildcard ::, and then fetches http://127.0.0.1:<port>. Now and then a request is answered by some other server: a 404 with no JSON body, or HTTPParserError 'Response does not match the HTTP/1.1 protocol'. The failing file passes when run alone, so treat this as a cross-file flake, not a regression in the PR under review. A likely fix is to bind and fetch the same address, e.g. listen(0, '127.0.0.1'). Separately, when you put a client request timeout under a fake clock, fake only setTimeout/clearTimeout and use a stub fetch that never answers. Node's real fetch (undici) sets its own timer through the global setTimeout while connecting, and that timer is lost when the real timers come back.
