behavior unhelpful for process kill default signal SIGTERM
See original GitHub issueSo, with Mocha’s programmatic API basically broken for running multiple times, I have a process that is spawn
ing 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:
.kill()
defaults to.kill('SIGTERM')
- 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 spawn
ed Mocha process.
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (4 by maintainers)
If there’s any way we can just avoid spawning in the first place, maybe this problem would magically disappear.
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!