Killing a child process returns exit code `0` instead of `null`

Open
#461 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
node.js, typescript

Research direction

The report provides reproducible child.js, cp.js, and pty.js examples; start by running them and comparing node-pty's exit event with Node.js child_process. Trace the process-exit handling used by pty.spawn and verify behavior for signal termination and process.exit(1). Done means the exitCode and signal values are consistent with the documented behavior, with coverage for both cases.

Written by the indexing model from the issue text.

Description

enhancement help wanted

Environment details

  • OS: macOS Big Sur
  • OS version: 11.1
  • node-pty version: 0.10.0

Issue description

I'm testing some things out with node-pty and noticed a difference between how Node.js child_process handles on exit and how node-pty handles them.

I wrote a small example.

child.js

Just a small program that logs tick every second.

setInterval(() => {
    console.log('tick');
}, 1000);
cp.js
const cp = require('child_process');

const child = cp.spawn('node', ['child.js']);

child.on('exit', (exitCode, signal) => {
    console.log(exitCode, signal);
});

child.kill('SIGINT');

When I run this code, it logs

null SIGINT

So, the exitCode is null here because it was killed with a signal like SIGINT.

pty.js
const pty = require('node-pty');

const child = pty.spawn('node', ['./child.js']);

child.onExit(({exitCode, signal}) => {
    console.log(exitCode, signal);
});

child.kill('SIGINT');

Doing the same with node-pty however, gives me the following result

0 2

2 is the numeric value of SIGINT, but the exit code is 0 indicating that the process exited just fine.

The same goes if the child.js kills itself with process.exit(1) for instance, the signal with child_process is null, but for node-pty it's 0.

I'm wondering if node-pty wants to be on par with how child_process works or if this is expected behaviour?

Thanks for the package though, it's awesome :)!

Dominant language
TypeScript
Stars
2k
Forks
337
Avg merge
21h 58m
Merged PRs (30d)
3

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/node-pty

All issues in microsoft/node-pty

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.