Skip to content

Commit

Permalink
Fix error caused by process dictionary not being reset
Browse files Browse the repository at this point in the history
  • Loading branch information
DaelonSuzuka committed Oct 27, 2023
1 parent e4eb88b commit 53fb1da
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/utils/subspawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand All @@ -20,29 +20,31 @@ 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));
});

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);
Expand Down

0 comments on commit 53fb1da

Please sign in to comment.