From 53fb1daccf2fd9f35dcef9b4916e7cf282ffd0ba Mon Sep 17 00:00:00 2001 From: David Kincaid Date: Fri, 27 Oct 2023 03:06:36 -0400 Subject: [PATCH] Fix error caused by process dictionary not being reset --- src/utils/subspawn.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/utils/subspawn.ts b/src/utils/subspawn.ts index f319a1b3c..b7c76763a 100644 --- a/src/utils/subspawn.ts +++ b/src/utils/subspawn.ts @@ -5,7 +5,7 @@ Original library copyright (c) 2022 Craig Wardman I had to vendor this library to fix the API in a couple places. */ -import { ChildProcess, execSync, spawn, SpawnOptions } from 'child_process'; +import { ChildProcess, execSync, spawn, SpawnOptions } from "child_process"; interface DictionaryOfStringChildProcessArray { [key: string]: ChildProcess[]; @@ -20,19 +20,21 @@ export function killSubProcesses(owner: string) { children[owner].forEach((c) => { try { if (c.pid) { - if (process.platform === 'win32') { + if (process.platform === "win32") { execSync(`taskkill /pid ${c.pid} /T /F`); } else { process.kill(-c.pid); } } - } catch { + } catch { console.log(`couldn't kill task ${owner}`); } }); + + children[owner] = []; } -process.on('exit', () => { +process.on("exit", () => { Object.keys(children).forEach((owner) => killSubProcesses(owner)); }); @@ -40,9 +42,9 @@ function gracefulExitHandler() { process.exit(); } -process.on('SIGINT', gracefulExitHandler); -process.on('SIGTERM', gracefulExitHandler); -process.on('SIGQUIT', gracefulExitHandler); +process.on("SIGINT", gracefulExitHandler); +process.on("SIGTERM", gracefulExitHandler); +process.on("SIGQUIT", gracefulExitHandler); export function subProcess(owner: string, command: string, options?: SpawnOptions) { const childProcess = spawn(command, options);