From 4fc04c8db38aa9bdadb295c7ff00f26e5ccaed50 Mon Sep 17 00:00:00 2001 From: Jussi Saurio Date: Wed, 4 Jun 2025 09:08:13 +0300 Subject: [PATCH] sim/aws: fix sim timeout handling code was trying to consume the same readablestream twice: once in the timeouter's catch block, and a second time in the body of the try block before postGithubIssue() could run. --- .../docker-entrypoint.simulator.ts | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/simulator-docker-runner/docker-entrypoint.simulator.ts b/simulator-docker-runner/docker-entrypoint.simulator.ts index 3b97e6ead..7d73bff6b 100644 --- a/simulator-docker-runner/docker-entrypoint.simulator.ts +++ b/simulator-docker-runner/docker-entrypoint.simulator.ts @@ -77,28 +77,9 @@ const run = async (seed: string, bin: string, args: string[]) => { }); const timeout = timeouter(PER_RUN_TIMEOUT_SECONDS, runNumber); - timeout.catch(async (err) => { - if (err instanceof TimeoutError) { - console.log(`Timeout on seed ${seed}, exiting...`); - proc.kill(); - const stdout = await new Response(proc.stdout).text(); - const stderr = await new Response(proc.stderr).text(); - const output = stdout + '\n' + stderr; - const seedForGithubIssue = seed; - const lastLines = output.split('\n').slice(-100).join('\n'); - console.log(`Simulator seed: ${seedForGithubIssue}`); - await github.postGitHubIssue({ - type: "timeout", - seed: seedForGithubIssue, - command: args.join(" "), - output: lastLines, - }); - process.exit(0); - } - }); try { - const exitCode = await proc.exited; + const exitCode = await Promise.race([proc.exited, timeout]); const stdout = await new Response(proc.stdout).text(); const stderr = await new Response(proc.stderr).text(); @@ -138,7 +119,24 @@ const run = async (seed: string, bin: string, args: string[]) => { } } } catch (err) { - throw err; + if (err instanceof TimeoutError) { + console.log(`Timeout on seed ${seed}, posting to Github...`); + proc.kill(); + const stdout = await new Response(proc.stdout).text(); + const stderr = await new Response(proc.stderr).text(); + const output = stdout + '\n' + stderr; + const seedForGithubIssue = seed; + const lastLines = output.split('\n').slice(-100).join('\n'); + console.log(`Simulator seed: ${seedForGithubIssue}`); + await github.postGitHubIssue({ + type: "timeout", + seed: seedForGithubIssue, + command: args.join(" "), + output: lastLines, + }); + } else { + throw err; + } } finally { // @ts-ignore timeout.clear();