Skip to content

Commit ef7768e

Browse files
committed
fix: sequential port probes and corrected test for non-required port overflow
- backendPort.ts: Replace concurrent Promise.all host probes with sequential loop to prevent EADDRINUSE self-interference when overlapping addresses (e.g. 127.0.0.1 and 0.0.0.0) bind to the same port simultaneously. - dev-runner.test.ts: Fix 'allows offsets where only non-required ports exceed max' test to actually exercise the edge case with the new BASE_SERVER_PORT. Use offset 51763 with requireServerPort=false/requireWebPort=true so the server port (65536) exceeds MAX_PORT while the web port (57496) stays in range.
1 parent 1213650 commit ef7768e

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

apps/desktop/src/backendPort.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,14 @@ export async function resolveDesktopBackendPort({
5858
// Keep desktop startup predictable across app restarts by probing upward from
5959
// the same preferred port instead of picking a fresh ephemeral port.
6060
for (let port = startPort; port <= maxPort; port += 1) {
61-
const availability = await Promise.all(
62-
hostsToCheck.map((candidateHost) => canListenOnHost(port, candidateHost)),
63-
);
64-
if (availability.every(Boolean)) {
61+
let allAvailable = true;
62+
for (const candidateHost of hostsToCheck) {
63+
if (!(await canListenOnHost(port, candidateHost))) {
64+
allAvailable = false;
65+
break;
66+
}
67+
}
68+
if (allAvailable) {
6569
return port;
6670
}
6771
}

scripts/dev-runner.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,13 @@ it.layer(NodeServices.layer)("dev-runner", (it) => {
246246
it.effect("allows offsets where only non-required ports exceed max", () =>
247247
Effect.gen(function* () {
248248
const offset = yield* findFirstAvailableOffset({
249-
startOffset: 51_762,
250-
requireServerPort: true,
251-
requireWebPort: false,
249+
startOffset: 51_763,
250+
requireServerPort: false,
251+
requireWebPort: true,
252252
checkPortAvailability: () => Effect.succeed(true),
253253
});
254254

255-
assert.equal(offset, 51_762);
255+
assert.equal(offset, 51_763);
256256
}),
257257
);
258258
});

0 commit comments

Comments
 (0)