Nodemon: Nodemon does not kill child process when SIGTERM is used?

Created on 18 Aug 2011  Â·  20Comments  Â·  Source: remy/nodemon

Maybe I am missing something, but when I use kill on the nodemon process, the child process hangs out there. Nodemon does not send any SIGTERM signal to the child process.

How to duplicate:

  1. Run the following command:
    NODE_PATH="/usr/lib/node_modules" nodemon /var/www/server.nodejs &
  2. Assume the PID returned is 9999
  3. Run kill -TERM 9999 (or just kill 9999, as SIGTERM is the default signal)
  4. Observe that the child process is still running

Most helpful comment

I'm running nodemon 1.9.1, inside docker container using node:latest image.
When running the image with CMD ["node", "index.js"], index.js receives SIGTERM.
When running with CMD ["nodemon", "-V", "index.js"] (verbose optional), container logs show "[nodemon] exiting", but sigterm is not received by index.js.

Nodemon appears to be working properly otherwise, just makes dev of cleanup tasks a little bit cumbersome.

edit: adding node version is v5.6.0

All 20 comments

What version of node are you running? I know there's been a new version out and I've not had a chance to test with it yet. Typically the child process should _not_ hang - but I'll do some digging to understand why - or feel free to check it out - nodemon's short and just JavaScript :)

Sorry - forgot to post version info
node -v
v0.4.10
nodemon -v
v0.5.3

0.5.4 fixes that now. I hadn't sent nodemon a TERM signal before, only hit ctrl+c to quit it. Tweaked, tested, closed :)

Perfect! Thanks for such a quick fix. npm update and now working properly.
You would think that the 'exit' event would be triggered when a SIGTERM signal was sent.

It happens again with 1.3.7:

✗ nodemon -v
v1.3.7

✗ ps -ef | grep node
cmpitg   25193 25026 13 16:38 pts/5    00:00:00 node /home/cmpitg/.npm-packages/bin/nodemon ua_parser_server/main.js
cmpitg   25206 25193  0 16:38 pts/5    00:00:00 sh -c node ua_parser_server/main.js
cmpitg   25207 25206 12 16:38 pts/5    00:00:00 node ua_parser_server/main.js

✗ kill 25193

✗ ps -ef | grep node
cmpitg   25207     1  3 16:38 pts/5    00:00:00 node ua_parser_server/main.js
cmpitg   25220 24643  0 16:38 pts/7    00:00:00 grep --color=auto node

✗ kill 25207

Any idea?

Issue is happening for myself on 1.3.7 as well. :+1:

Any update on this? This is interrupting our development build process because we need to manually send a sigkill event to node in order to actually kill the process. Using 1.3.7

+1

Same here, using 1.8.1

This is also biting me, Please reopen.

Those plusoneing and asking to reopen: since you've not included any details, are you saying you replicate the issue in the exact same way as the original post 4 years ago when nodemon was at 1.2?

Hi, thanks for your quick response. I put together this test script:

#!/usr/local/bin/node

process.on('SIGINT', () => {
      console.log('SIGINT');
      process.exit(0);
});
process.on('SIGTERM', () => {
      console.log('SIGTERM');
      process.exit(0);
});
process.on('SIGUSR2', () => {
      console.log('SIGUSR2');
      process.exit(0);
});
process.on('exit', () => {
      console.log('exit');
      process.exit(0);
});

runstuff();

function runstuff () {
    console.log('loop');
    setTimeout(runstuff, 2000);
}

running this with nodemon and then killing nodemon leaves the script running:

$ ps aux | grep -i test.js
fantapop   13008  4.6  0.2 1204924 33092 pts/33  Sl+  23:52   0:00 node node_modules/grunt-nodemon/node_modules/nodemon/bin/nodemon.js test.js
fantapop   13019  0.0  0.0   4440   656 pts/33   S+   23:52   0:00 sh -c node test.js
fantapop   13020  0.5  0.0 641156 14792 pts/33   Sl+  23:52   0:00 node test.js
fantapop   13026  0.0  0.0  11740   960 pts/59   R+   23:52   0:00 grep -H --color=always -i test.js
$ kill 13008
$ ps aux | grep -i test.js
fantapop   13020  0.2  0.0 641156 14792 pts/33   Sl   23:52   0:00 node test.js
fantapop   13033  0.0  0.0  11740   960 pts/59   R+   23:52   0:00 grep -H --color=always -i test.js

@fantapop doesn't replicate on my machine. I see you're using nodemon from inside of grunt-nodemon. Are you actually using [email protected]?

I've confirmed nodemon version 1.8.1.

This is on ubuntu 14.04.

Anything else I can check for?

I'm on Ubuntu 15.10 and cannot replicate with the test script @fantapop created, but I came here because I have been experiencing issues with nodemon _sometimes_ not killing the child process.

I'm running nodemon 1.9.1, inside docker container using node:latest image.
When running the image with CMD ["node", "index.js"], index.js receives SIGTERM.
When running with CMD ["nodemon", "-V", "index.js"] (verbose optional), container logs show "[nodemon] exiting", but sigterm is not received by index.js.

Nodemon appears to be working properly otherwise, just makes dev of cleanup tasks a little bit cumbersome.

edit: adding node version is v5.6.0

It should send sigterm to the underlying process and wait right? That is what everyone is expecting since 2011? 😃

Does anyone have a workaround for this? Especially when the subprocess uses chokidar, this bug is a nightmare.

Worked around the problem by using the nodemon.json (see full doc with nodemon --help config)

{
  "events": {
    "restart": "pkill -f partial/path/to/child/of/child"
  }
}

Not sure why this Issue is closed, should be open.

Edit: nodemon --signal SIGTERM or nodemon.json with

{
  "signal": "SIGTERM"
}

works too.

@stoically probably because the original issue was raised over 6 years ago and doesn't relate, in any way what so ever, to [email protected].

Well, you're right. The original problem (sending TERM to nodemon not killing the child) doesn't exist anymore in 1.13.2 (didn't updated for 2 weeks or something and hence didn't notice, oops).

The other mentioned problem (and what actually affects me) in this thread still exists tho. When restarting after file change the child process does not receive SIGTERM or process exit event (only SIGUSR2).

Sorry for the tone and hijacking a 6 year old issue. Also thanks for your work on nodemon!

Host: Ubuntu 16.04.3 / 4.4.0-104-generic
Node: 8.7.0 (nvm: 0.33.5)

Edit: I'll get a reproducable test-case ready and open a new issue
Edit2: Here's the issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Bastorx picture Bastorx  Â·  5Comments

endquote picture endquote  Â·  4Comments

maotora picture maotora  Â·  4Comments

binarykitchen picture binarykitchen  Â·  5Comments

jagged3dge picture jagged3dge  Â·  4Comments