From b7c8fce83cd087fd4e2a7601f8dd3c80f92d80cc Mon Sep 17 00:00:00 2001 From: can1357 Date: Sat, 18 Jul 2026 19:34:02 +0200 Subject: [PATCH] fix(stats): bind port-conflict test listeners to the wildcard address On macOS SO_REUSEADDR lets startServer's wildcard bind coexist with a 127.0.0.1-only listener, so the EADDRINUSE path was never exercised and three of the four conflict tests failed. Wildcard-bind the holders and the reused dashboard so the conflict is real on every platform. --- packages/stats/test/server-port-conflict.test.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/stats/test/server-port-conflict.test.ts b/packages/stats/test/server-port-conflict.test.ts index e08f69ceb..771953bdd 100644 --- a/packages/stats/test/server-port-conflict.test.ts +++ b/packages/stats/test/server-port-conflict.test.ts @@ -6,15 +6,17 @@ import { startServer } from "../src/server"; const holderProcesses: Array> = []; async function startBunHolder(responseExpr: string, options?: { statsOwned?: boolean }) { + // Bind the wildcard address: `startServer` binds the wildcard too, and on + // macOS SO_REUSEADDR lets a wildcard bind coexist with a 127.0.0.1-only + // listener, which would bypass the EADDRINUSE path this suite exercises. const reservation = Bun.serve({ - hostname: "127.0.0.1", port: 0, fetch: () => new Response("reserved"), }); const port = reservation.port; reservation.stop(true); - const source = `Bun.serve({ hostname: "127.0.0.1", port: ${port}, fetch: () => ${responseExpr} }); process.stdout.write("ready"); await Promise.withResolvers().promise;`; + const source = `Bun.serve({ port: ${port}, fetch: () => ${responseExpr} }); process.stdout.write("ready"); await Promise.withResolvers().promise;`; const args = [process.execPath, "-e", source]; if (options?.statsOwned) args.push("omp-stats"); const child = Bun.spawn(args, { @@ -47,7 +49,6 @@ afterEach(async () => { describe("startServer port conflicts", () => { it("reuses a live stats dashboard identified by its header", async () => { const existing = Bun.serve({ - hostname: "127.0.0.1", port: 0, fetch: request => new URL(request.url).pathname === "/api/stats/models"