Skip to content

Commit 6696c33

Browse files
committed
fix: put the bun script's port range above every other dev script
The previous commit moved this script to base 9850 and called the bases disjoint. They are not. A base only separates two files if the earlier one's modulus window stops before the later one's base, and these windows run well past: reload-retry reaches 9739, hot-reload 9949, extra-watch 9989, overlay-scope 9979. So 9850-9989 landed inside three of them, where the old 9500-9739 had overlapped two. The change made the collision it claimed to fix more likely, and narrowing the modulus to 140 also raised the same-file rate the comment credited it with lowering. 9989 is the highest port any existing script reaches, so this takes 10000-10255, which cannot collide with any of the four for any pair of pids, and restores a modulus at least as wide as the original for the same-file case. The overlapping ranges among the other four are pre-existing and left alone.
1 parent 21dfc1d commit 6696c33

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

test/bun/dev-public-before-warm.mjs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,19 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
3333
const ROOT = resolve(__dirname, '../..');
3434
const CLI = join(ROOT, 'packages/cli/bin/webjs.js');
3535
const runtime = process.versions.bun ? `bun ${process.versions.bun}` : `node ${process.versions.node}`;
36-
// Own base, disjoint from every other dev-server bun script (dev-reload-retry
37-
// 9500, dev-hot-reload 9700, dev-extra-watch 9750, dev-overlay-scope 9800).
38-
// The modulus separates concurrent RUNS of this file; the distinct base is what
39-
// separates this file from the others, since the node runner can schedule the
40-
// `*.test.mjs` wrappers concurrently in separate child processes.
41-
const PORT = 9850 + (process.pid % 140);
36+
// A distinct base is NOT enough on its own, which is the trap here: a base
37+
// only separates two files if the earlier one's modulus window stops before
38+
// the later one's base, and among the existing dev-server scripts it does not.
39+
// Their reachable RANGES are dev-reload-retry 9500-9739, dev-hot-reload
40+
// 9700-9949, dev-extra-watch 9750-9989 and dev-overlay-scope 9800-9979, which
41+
// overlap each other freely. That is pre-existing and not this file's to fix;
42+
// what this file can do is sit entirely ABOVE all of them. 9989 is the highest
43+
// port any of them reaches, so 10000-10255 cannot collide with any of the four
44+
// for any pair of pids. The modulus then separates concurrent RUNS of this
45+
// file, which is the only collision left. Both halves matter, because the node
46+
// runner schedules the `*.test.mjs` wrappers concurrently in separate child
47+
// processes with near-consecutive pids.
48+
const PORT = 10000 + (process.pid % 256);
4249
const BASE = `http://localhost:${PORT}`;
4350

4451
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));

0 commit comments

Comments
 (0)