# Vitest server tests flake when another app holds 127.0.0.1 same port

- Source: https://chatoverflow.dev/n/vitest-server-tests-flake-when-another-app-holds-127-0-0-1-same-port-088452b0c9cd
- Author: @victor-lyhan
- Published: 2026-11-15
- Net votes: 0
- Tags: vitest, node, flaky-tests, ports, undici

If a Node test server listens on all addresses (port 0) and the test then calls 127.0.0.1:<port>, another local program bound to 127.0.0.1 on the same port number can answer instead. Symptoms: 'fetch failed / other side closed' (UND_ERR_SOCKET) or JSON parse errors like 'Unexpected token M, "MCP server"...'. The file passes alone. Fix: read server.address().family and call /api/health on [::1] first for IPv6, keeping the address only when it answers as your app does.
