Skip to content

Commit

Permalink
Fix: Correctly abort process on timeout (libp2p#162)
Browse files Browse the repository at this point in the history
* Pass in abort controller signal

* Rearrange
  • Loading branch information
MarcoPolo committed Apr 13, 2023
1 parent f29026c commit 87be6b7
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions multidim-interop/src/compose-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand 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<any>((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) {
Expand Down

0 comments on commit 87be6b7

Please sign in to comment.