Skip to content

Commit

Permalink
fix: handle the posibility that the process tree is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Jun 22, 2023
1 parent be562ef commit 5070b01
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/killPsTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@ export const killPsTree = async (
rootPid: number,
gracefulTimeout: number = 30_000,
) => {
const pids = await pidTree(rootPid, {
root: true,
});
let pids: number[] = [];

try {
pids = await pidTree(rootPid, {
root: true,
});
} catch (error) {
log.warn({ error }, 'failed to find process tree');

return false;
}

for (const pid of pids) {
try {
Expand Down Expand Up @@ -65,4 +73,6 @@ export const killPsTree = async (
clearTimeout(timeoutId);

log.debug('all processes terminated');

return true;
};

0 comments on commit 5070b01

Please sign in to comment.