Skip to content

Commit 0d90f0f

Browse files
committed
test(daemon-server): bind blocker to 0.0.0.0 so EADDRINUSE fires on macOS/Windows
Previous version bound the blocker to 127.0.0.1, but express.listen(port) binds to 0.0.0.0 (no host arg). On BSD-derived stacks (macOS, Windows) a 127.0.0.1 bind and a 0.0.0.0 bind on the same port can coexist, so the daemon's wildcard listen succeeded and the test asserted rejection but got a resolved promise. Linux is stricter and treats this as a conflict, which is why ubuntu passed but the other runners failed.
1 parent 6a2f9da commit 0d90f0f

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

test/webui/daemon-server.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import { startDaemonServer } from "../../dist/webui/daemon-server.js";
1111
// The contract we want: if the port can't be bound, startDaemonServer must reject.
1212
describe("startDaemonServer bind contract", () => {
1313
it("rejects when the RPC port is already taken (regression for issue #42)", async () => {
14+
// Blocker must bind to 0.0.0.0 because express.listen(port) (no host arg) also
15+
// binds to 0.0.0.0. On BSD-derived stacks (macOS, Windows) a wildcard bind and
16+
// a 127.0.0.1 bind on the same port can coexist, so binding the blocker to
17+
// 127.0.0.1 would let the daemon's wildcard bind succeed and the test wouldn't
18+
// exercise the EADDRINUSE path.
1419
const blocker = net.createServer();
1520
const port = await new Promise<number>((resolve, reject) => {
1621
blocker.once("listening", () => {
@@ -19,7 +24,7 @@ describe("startDaemonServer bind contract", () => {
1924
else reject(new Error(`unexpected address ${JSON.stringify(addr)}`));
2025
});
2126
blocker.once("error", reject);
22-
blocker.listen(0, "127.0.0.1");
27+
blocker.listen(0, "0.0.0.0");
2328
});
2429

2530
// Swallow any stray uncaughtException emitted by an unguarded server.listen()

0 commit comments

Comments
 (0)