Skip to content

Commit 3de8c66

Browse files
committed
fix: handle ps.tree() failure gracefully in kill() on Alpine Linux
On Alpine Linux (and other environments using BusyBox), the ps output format differs from standard GNU/procps ps. The @webpod/ingrid parser used by @webpod/ps cannot parse BusyBox output and throws a TypeError when kill() attempts to collect child processes via ps.tree(). Wrap the ps.tree() loop in a try/catch so that parse failures fall through to the direct process.kill() call below. The parent process is still killed; child processes may survive in degraded environments, but the caller no longer receives an unexpected TypeError. Fixes #1369
1 parent 98531fc commit 3de8c66

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/core.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,10 +1079,16 @@ export async function kill(
10791079
)
10801080
return
10811081

1082-
for (const p of await ps.tree({ pid, recursive: true })) {
1083-
try {
1084-
process.kill(+p.pid, signal)
1085-
} catch (e) {}
1082+
try {
1083+
for (const p of await ps.tree({ pid, recursive: true })) {
1084+
try {
1085+
process.kill(+p.pid, signal)
1086+
} catch (e) {}
1087+
}
1088+
} catch (e) {
1089+
// ps.tree() can fail on non-standard ps implementations (e.g. BusyBox on
1090+
// Alpine Linux) that produce output the parser cannot handle. Fall through
1091+
// to the direct process.kill() below so the parent process is still killed.
10861092
}
10871093
try {
10881094
process.kill(-pid, signal)

0 commit comments

Comments
 (0)