Skip to content

Document what IPty.kill() does on Unix - #1026

Open
AI Automation Engineer | OLL4.com (oll4com) wants to merge 1 commit into
microsoft:mainfrom
oll4com:docs/kill-unix-behaviour
Open

AI Automation Engineer | OLL4.com (oll4com) wants to merge 1 commit into
microsoft:mainfrom
oll4com:docs/kill-unix-behaviour

Conversation

@oll4com

Copy link
Copy Markdown

The typings describe kill() as "Kills the pty". On Unix it actually calls process.kill(this.pid, signal) inside a try/catch that ignores every error (src/unixTerminal.ts). Two things follow that callers can't see from the docs:

  • only the spawned process gets the signal, not its process group or other descendants, so a child that ignores SIGHUP keeps running after the shell is gone;
  • a mistyped signal name or a process that already exited fails silently.

Repro on Linux (current main, Node 26):

const pty = require('node-pty');
const p = pty.spawn('/bin/sh', ['-c', 'trap "" HUP; sleep 300 & echo CHILD=$!; wait'], {});
// after CHILD=<pid> is printed:
p.kill('SIGTERM');              // sh exits, the sleep is still alive
// process.kill(-p.pid, 'SIGTERM') instead stops both

p.kill('SIGNOPE');              // no error; process.kill(pid, 'SIGNOPE') throws ERR_UNKNOWN_SIGNAL

This only adds a paragraph to the kill() JSDoc in typings/node-pty.d.ts that says this and points to process.kill(-pty.pid, signal) for the process group, with the caveat that an interactive shell puts its jobs in their own groups. No code change.

Tested: ran the repro above against a local build; npx tsc --noEmit typings/node-pty.d.ts passes; npm test passes (20 passing, lint clean).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant