question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

behavior unhelpful for process kill default signal SIGTERM

See original GitHub issue

So, with Mocha’s programmatic API basically broken for running multiple times, I have a process that is spawning the commandline Mocha to run multiple times on demand. Then there’s also the ability to stop one of these instances on demand. Naturally, child-process’s .kill method makes that easy, right?

Today I learned:

  1. .kill() defaults to .kill('SIGTERM')
  2. SIGTERM kills the mocha instance without affecting the _mocha instance that is actually running the tests. [SEE UPDATE…] Not only that, but it seemed like it exited with code 0 reporting no signal stopped it (but I’d have to double-check that, as I was experimenting trying to see if I could find an easy fix, so it’s possible my experiments were causing that bit). [UPDATE: Ran a quick double-check, and it seems to exit with no exit code and signal SIGTERM; exiting with code 0 and no signal reported must have been what happened when I tried to get Mocha to handle SIGTERM (see below).]

(This came up on a Mac using Node 6. I could fairly easily put together an integration test to demonstrate the issue if we wanted to see what all environments it affects, I think…)

Obviously, this is easy to handle outside of Mocha: use .kill('SIGINT') instead of .kill(). But it was such counterintuitive and unhelpful default behavior, and considering that the alternative to spawn (the programmatic API) is known to be broken in some cases, that I’m somewhat surprised we don’t appear to have any existing issues about it.

Anyway, does anyone know what it would take to fix this? I tried adding a SIGTERM handler and a process.on(‘exit’ … handler to the mocha file that runs _mocha, but couldn’t really get clean results like for SIGINT – but maybe I was doing something wrong. I just figure that it’s probably not worth it if it’s difficult, but would be very much worth it if it happens to be easy. I know we’re also considering switching to a library that would handle the Node flag spawning mechanism for us (#2517); I would be interested in seeing what happens if we use that and send .kill() to a spawned Mocha process.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
boneskullcommented, Oct 6, 2017

If there’s any way we can just avoid spawning in the first place, maybe this problem would magically disappear.

0reactions
github-actions[bot]commented, Mar 28, 2021

This issue hasn’t had any recent activity, and I’m labeling it stale. Remove the label or comment or this issue will be closed in 14 days. Thanks for contributing to Mocha!

Read more comments on GitHub >

github_iconTop Results From Across the Web

In the absence of a signal handler, does SIGTERM behave ...
In the absence of any signal configuration, SIGTERM and SIGKILL are in practice equivalent, at least from the killed process's perspective, ...
Read more >
kill - End a process or job, or send it a signal - IBM
kill ends a process by sending it a signal. The default signal is SIGTERM. kill is a built-in shell command. In the tcsh...
Read more >
What is the default behaviour of Node.js on receiving SIGTERM?
When no handler is added for SIGTERM , node will reset the terminal and exit the process immediately. It's a "drop everything where...
Read more >
questions about signals - wizard zines
kill without any argument sends the SIGTERM signal. The default behavior for processes when they get a SIGTERM is to exit immediately.
Read more >
Killing a process and all of its descendants - Morning Coffee
We used a negative number -19701 to send a signal to the group. If kill receives a positive number, it kills the process...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found