From ee3a3ba8c525af3e3a9f2806bf65668622e7ae67 Mon Sep 17 00:00:00 2001 From: "paseo-bot[bot]" <266920839+paseo-bot[bot]@users.noreply.github.com> Date: Mon, 16 Nov 2026 06:03:13 +0000 Subject: [PATCH] test(app): pick a new port when an isolated daemon loses its reserved one (#9815) The isolated host daemon helper reserves a port, releases it, and passes it to the daemon. Another process can bind it in between, and the daemon exits with EADDRINUSE. That failed a Playwright worker's own daemon in the e2eWorker fixture. The first start now reserves a fresh port and starts again when the daemon reports EADDRINUSE; restart() keeps the endpoint the app already knows. Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 --- .../support/helpers/isolated-host-daemon.ts | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/app/e2e/support/helpers/isolated-host-daemon.ts b/packages/app/e2e/support/helpers/isolated-host-daemon.ts index dea61c3a3..3aab184cc 100644 --- a/packages/app/e2e/support/helpers/isolated-host-daemon.ts +++ b/packages/app/e2e/support/helpers/isolated-host-daemon.ts @@ -121,7 +121,7 @@ export async function startIsolatedHostDaemon( serverId: string, options: IsolatedHostDaemonOptions = {}, ): Promise { - const port = await getAvailableHostDaemonPort(); + let port = await getAvailableHostDaemonPort(); const metroPort = process.env.E2E_METRO_PORT; if (!metroPort) throw new Error("E2E_METRO_PORT is required to start an isolated host daemon"); @@ -231,8 +231,25 @@ export async function startIsolatedHostDaemon( } }; + // The reserved port is released before the daemon binds it, so another + // process can take it in between. Only the first start picks a new port: + // restart() keeps the endpoint the app already knows. + const startOnFreePort = async (): Promise => { + for (let attempt = 1; ; attempt += 1) { + try { + await spawnDaemon(); + return; + } catch (error) { + const lostPort = error instanceof Error && error.message.includes("EADDRINUSE"); + if (!lostPort || attempt === 3) throw error; + await stopDaemon(); + port = await getAvailableHostDaemonPort(); + } + } + }; + try { - await spawnDaemon(); + await startOnFreePort(); } catch (error) { await stopDaemon(); if (!options.preserveHome) {