From d342ac541ed0c805b140712ac4f7d6440e64ff01 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Sat, 8 Apr 2023 10:53:38 -0700 Subject: [PATCH] Fix: Correctly abort process on timeout (#162) * Pass in abort controller signal * Rearrange --- multidim-interop/src/compose-runner.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/multidim-interop/src/compose-runner.ts b/multidim-interop/src/compose-runner.ts index 2ad9982..b4e9e28 100644 --- a/multidim-interop/src/compose-runner.ts +++ b/multidim-interop/src/compose-runner.ts @@ -8,6 +8,7 @@ import { ComposeSpecification, PropertiesServices } from "../compose-spec/compos import { stringify } from 'yaml'; const exec = util.promisify(execStd); +const timeoutSecs = 3 * 60 export type RunOpts = { up: { @@ -43,14 +44,10 @@ export async function run(namespace: string, compose: ComposeSpecification, opts } try { - const timeoutSecs = 3 * 60 - let timeoutId - const { stdout, stderr } = - (await Promise.race([ - exec(`docker compose -f ${path.join(dir, "compose.yaml")} up ${upFlags.join(" ")}`), - // Timeout - uses any type because this will only reject the promise. - new Promise((resolve, reject) => { timeoutId = setTimeout(() => reject("Timeout"), 1000 * timeoutSecs) }) - ])) + const controller = new AbortController(); + const timeoutId = setTimeout(() => controller.abort(), 1000 * timeoutSecs) + const { signal } = controller; + const { stdout, stderr } = await exec(`docker compose -f ${path.join(dir, "compose.yaml")} up ${upFlags.join(" ")}`, { signal }) clearTimeout(timeoutId) const testResults = stdout.match(/.*dialer.*({.*)/) if (testResults === null || testResults.length < 2) {