fix: handle ps.tree() failure gracefully in kill() on Alpine Linux#1441
fix: handle ps.tree() failure gracefully in kill() on Alpine Linux#1441Luc0-0 wants to merge 2 commits intogoogle:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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 google#1369
bd21d3d to
3de8c66
Compare
|
This is not a fix, but a workaroud. We should figure out what exactly goes wrong with BusyBox + ps. |
|
Traced it — Root fix would be a Kept the try/catch here so |
|
Opened the upstream fixes btw:
Once those land and get re-vendored, the try/catch here becomes redundant. Until then it keeps kill() from blowing up on Alpine. |
Problem
On Alpine Linux (and other environments using BusyBox),
kill()throws an unexpectedTypeErrorinstead of killing the process:This was introduced in v8.8.4 when
@webpod/psreplaced the previous process tree implementation. BusyBoxpsproduces output in a format that@webpod/ingridcannot parse — it returns an empty array, causinglines[0].spacesto throw.Reported in #1369.
Fix
Wrap the
ps.tree()loop in a try/catch insrc/core.ts. If the process tree lookup fails (e.g. due to an unrecognisedpsoutput format), execution falls through to the existingprocess.kill(pid)call below, which still terminates the target process. Child processes may not be killed in degraded environments, but the caller no longer receives an unexpected error.The root cause is in
@webpod/ingrid's parser — a fix there would be more complete — but this makeskill()robust against any future parser failures as well.