Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions test/js/bun/module-graph/module-graph-io.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -885,12 +885,12 @@ describe.concurrent("ModuleGraph: an error in what a graph opened is the graph's
dropRedisConnections() {
for (const socket of host.redisConnections.splice(0)) socket.end();
},
async closedUdpPort() {
// Taken until close(): a socket made for sending to the port cannot be given that very port
// as its own, which would leave it hearing itself and never refused.
async udpPortToClose() {
const s = dgram.createSocket("udp4");
await new Promise(r => s.bind(0, "127.0.0.1", r));
const port = s.address().port;
await new Promise(r => s.close(r));
return port;
return { port: s.address().port, close: () => new Promise(r => s.close(r)) };
},
};
`;
Expand Down Expand Up @@ -1052,8 +1052,10 @@ describe.concurrent("ModuleGraph: an error in what a graph opened is the graph's
import { host } from "./host.mjs";
const { promise, resolve } = Promise.withResolvers();
process.on("uncaughtException", error => resolve("host: " + error.code));
const graph = new Bun.ModuleGraph({ globals: { closedPort: await host.closedUdpPort() }, onError: error => resolve("graph: " + error.code) });
const { port, close } = await host.udpPortToClose();
const graph = new Bun.ModuleGraph({ globals: { closedPort: port }, onError: error => resolve("graph: " + error.code) });
const { stop } = await graph.import(import.meta.dir + "/tenant.mjs");
await close();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟣 pre-existing, not blocking: The test can still hang or go wrong when another process takes the freed port, and after merging this remains a flake for CI runs of this file. After close() at test/js/bun/module-graph/module-graph-io.test.ts:1058 the port is free while the tenant keeps sending every 5 ms; a sibling case in the same describe.concurrent binds port 0 at line 937 with data: boom and never closes it, so if it is handed that port the datagrams are delivered, not refused, and boom fires in the sibling for a packet it never expected. Fix: keep the port taken for the whole test (hold the host socket and make the graph socket's error come from a port that cannot be reassigned, e.g. an unroutable or firewalled target, or assert with a bounded deadline and a stated reason).
A small fix can ride a push you are already making; otherwise a short reply is enough.

Why this was flagged

The sibling test at test/js/bun/module-graph/module-graph-io.test.ts:898 runs concurrently as its own process (describe.concurrent) and its cases at lines 937 and 954 bind UDP port 0 on 127.0.0.1; the line-937 Bun.udpSocket is never closed, so it lives until that process exits (up to the 60 s timeout at line 1038). After await close() at line 1058 the port P is free, and the kernel can hand it to that sibling bind. Then every 5 ms send from tenant.mjs line 1048 is delivered to the sibling's socket: no ICMP unreachable, no on_recv_error (src/runtime/socket/udp_socket.rs:97), no graph: ECONNREFUSED, and the sibling's data: boom runs for a packet from another test. On base (line 1055 old closedUdpPort) the port was freed earlier, so the exposure is not widened, but this residual path still makes the awaited promise at line 1059 wait for an unrelated process to exit. Remedy: keep the port owned (or the error source deterministic) for the whole test rather than freeing it mid-test.

Verification: Pre-existing and narrowed by this PR. After await close() at /home/claude/bun/test/js/bun/module-graph/module-graph-io.test.ts:1058 the host's dgram socket no longer owns P; if another socket binds P before the tenant's next send draws ICMP port-unreachable, every 5 ms "x" is delivered instead of refused, and await promise at line 1059 never settles. Nothing in the diff rules this out.

console.log(await promise);
stop();
process.exit(0);
Expand Down
Loading