Skip to content

Commit 6264868

Browse files
fix(scripts): poll for environment-id instead of one-shot read
The showcase server starts accepting connections before its ServerEnvironment layer persists userdata/environment-id, so reading the file immediately after waitForPort races server startup. The fast macOS runner lost that race (ENOENT); poll for non-empty content with the same timeout discipline as waitForPort. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent cf3855e commit 6264868

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

‎scripts/mobile-showcase.ts‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,23 @@ async function waitForPort(port: number, label = "Process", timeoutMs = 60_000):
500500
throw new Error(`${label} did not begin listening on port ${port} within ${timeoutMs}ms.`);
501501
}
502502

503+
async function waitForFileContent(
504+
filePath: string,
505+
label: string,
506+
timeoutMs = 60_000,
507+
): Promise<string> {
508+
const deadline = Date.now() + timeoutMs;
509+
while (Date.now() < deadline) {
510+
const content = await NodeFSP.readFile(filePath, "utf8").then(
511+
(value) => value.trim(),
512+
() => "",
513+
);
514+
if (content) return content;
515+
await delay(250);
516+
}
517+
throw new Error(`${label} was not written to ${filePath} within ${timeoutMs}ms.`);
518+
}
519+
503520
async function reserveAvailablePort(): Promise<number> {
504521
return await new Promise<number>((resolve, reject) => {
505522
const server = NodeNet.createServer();
@@ -1225,12 +1242,12 @@ async function main(): Promise<void> {
12251242
showcaseServers.push(server);
12261243
await waitForPort(port, `${environment.label} server`);
12271244
await seedShowcaseEnvironment({ baseDir, projectIds: environment.projectIds });
1228-
const environmentId = (
1229-
await NodeFSP.readFile(NodePath.join(baseDir, "userdata", "environment-id"), "utf8")
1230-
).trim();
1231-
if (!environmentId) {
1232-
throw new Error(`${environment.label} did not persist an environment id.`);
1233-
}
1245+
// The server begins listening before the ServerEnvironment layer
1246+
// persists the environment id, so poll rather than read once.
1247+
const environmentId = await waitForFileContent(
1248+
NodePath.join(baseDir, "userdata", "environment-id"),
1249+
`${environment.label} environment id`,
1250+
);
12341251
showcaseEnvironments.push({ baseDir, environmentId, label: environment.label, port });
12351252
}
12361253

0 commit comments

Comments
 (0)