zx icon indicating copy to clipboard operation
zx copied to clipboard

[Bug]: TypeError when using `.kill()` on Alpine Linux in zx v8.8.4+

Open examan opened this issue 2 months ago • 3 comments

What happened?

Calling .kill() on a ProcessPromise results in a TypeError on Alpine Linux in zx versions v8.8.4 and later. This worked correctly in v8.8.3.

The regression is likely caused by ps-tree failing to parse the output of BusyBox's ps command on Alpine.

How it should work?

.kill() should run without error and terminate the process.

How to reproduce the bug?

import { $ } from 'zx';

await $`sleep 10`.nothrow().kill();

Version

8.8.5

What's OS kind?

Linux

What JS runtime is used?

Node.js

Runtime Version

24.11.1

Error stack / relevant log output

/fx-src/node_modules/zx/build/vendor-core.cjs:825
var getBorders = (lines) => lines[0].spaces.reduce((m, i) => {
                                     ^

TypeError: Cannot read properties of undefined (reading 'spaces')
    at getBorders (/fx-src/node_modules/zx/build/vendor-core.cjs:825:38)
    at parseUnixGrid (/fx-src/node_modules/zx/build/vendor-core.cjs:834:19)
    at parse (/fx-src/node_modules/zx/build/vendor-core.cjs:945:10)
    at parse (/fx-src/node_modules/zx/build/vendor-core.cjs:1211:14)
    at Object.callback (/fx-src/node_modules/zx/build/vendor-core.cjs:1268:54)
    at ChildProcess.<anonymous> (/fx-src/node_modules/zx/build/vendor-core.cjs:1169:13)
    at Object.onceWrapper (node:events:623:26)
    at ChildProcess.emit (node:events:508:28)
    at maybeClose (node:internal/child_process:1101:16)
    at Socket.<anonymous> (node:internal/child_process:457:11)

Code of Conduct

  • [x] I agree to follow this project's Code of Conduct

examan avatar Nov 28 '25 08:11 examan

Hey @examan,

Could you plz add raw output fixture example? This way we can improve the parser logic.

antongolub avatar Nov 28 '25 08:11 antongolub

Here is the ps output I captured:

PID   USER     TIME  COMMAND
    1 webmail   0:00 sleep infinity
    8 webmail   0:00 /bin/bash
   21 webmail   0:00 ps

Would this information be sufficient for debugging, or do you need more details?

examan avatar Dec 02 '25 04:12 examan

@examan,

output is fine, but it seems, getBorders got empty lines collection. How it works internally:

  1. zx calls ps -lx
  2. output is empty → lines[0] is undefined → getBorders fails
  3. @webpod/ps invokes zurk/spawn's exec(). defaults.stdio is ['pipe', 'pipe', 'pipe']. There is no logic in this. I'm stuck here, I still can’t understand why the output turned out to be empty. Permissions issue?

antongolub avatar Dec 02 '25 18:12 antongolub

@antongolub

Let me know if there’s any additional information I can provide to help move this forward.

examan avatar Dec 12 '25 18:12 examan