Hi Remy,
I launch nodemon like this:
Mac:webserv tito$ nodemon app.js
15 Jun 13:05:08 - [nodemon] v0.7.8
15 Jun 13:05:08 - [nodemon] to restart at any time, enter `rs`
15 Jun 13:05:08 - [nodemon] watching: /Users/tito/Desktop/Tests/webserv
15 Jun 13:05:08 - [nodemon] starting `node app.js`
Express server listening on port 8080 in development mode
I can see two instances of node showing up in Activity Monitor (Mac OS X). If I terminate nodemon via Control-C, one instance is left behind. When I fire nodemon again I get the following:
Mac:webserv tito$ nodemon app.js
15 Jun 13:07:10 - [nodemon] v0.7.8
15 Jun 13:07:10 - [nodemon] to restart at any time, enter `rs`
15 Jun 13:07:10 - [nodemon] watching: /Users/tito/Desktop/Tests/webserv
15 Jun 13:07:10 - [nodemon] starting `node app.js`
Caught exception: Error: listen EADDRINUSE
Is this expected? Is there anything I can do to make sure nodemon kills the two processes it created when it launched?
Thanks!
No, it's not expected behaviour. For some reason your child process isn't
terminating.
Can you post up a simplified version of your app.js that doesn't terminate
when you do ctrl+c?
On Saturday, June 15, 2013, Tito Ciuro wrote:
Hi Remy,
I launch nodemon like this:
Mac:webserv tito$ nodemon app.js
15 Jun 13:05:08 - [nodemon] v0.7.8
15 Jun 13:05:08 - [nodemon] to restart at any time, enterrs
15 Jun 13:05:08 - [nodemon] watching: /Users/tito/Desktop/Tests/webserv
15 Jun 13:05:08 - [nodemon] startingnode app.js
Express server listening on port 8080 in development modeI can see two instances of node showing up in Activity Monitor (Mac OS X).
If I terminate nodemon via Control-C, one instance is left behind. When I
fire nodemon again I get the following:Mac:webserv tito$ nodemon app.js
15 Jun 13:07:10 - [nodemon] v0.7.8
15 Jun 13:07:10 - [nodemon] to restart at any time, enterrs
15 Jun 13:07:10 - [nodemon] watching: /Users/tito/Desktop/Tests/webserv
15 Jun 13:07:10 - [nodemon] startingnode app.js
Caught exception: Error: listen EADDRINUSEIs this expected? Is there anything I can do to make sure nodemon kills
the two processes it created when it launched?Thanks!
—
Reply to this email directly or view it on GitHubhttps://github.com/remy/nodemon/issues/185
.
— Remy
I'm seeing the same behavior on Windows 7 with a bare bones express app when running nodemon from a Cygwin terminal. If I run from a regular windows command prompt then it works ok.
I have the same when I do (on a debian):
echo `PORT=8000 nodemon index.coffee > /dev/null 2>&1 & echo $!` > /var/run/myapp.pid kill -9 $(cat /var/run/myapp.pid)
nodemon exits but node stays.
But with Ctrl+C, no problem.
@kylekatarnls by sending the 9 you're sending the SIGKILL signal, which "cannot be caught or ignored.". So nodemon has no time to clean up. You should only use SIGKILL for forceable kill processes. More appropriate is the SIGTERM or 15 to tell nodemon to shutdown.
Thanks!
I'm using OSX, and I'm getting this error intermittently. It seems that nodemon restarts the process a little too quickly sometimes. Maybe one out of 10+ times? It only started happening recently, but it's happening across multiple computers/projects.
I'm experiencing something similar to @bjmiller on OS X.
Same here on WIndows 10 running from cygwin. Stopping nodemon leaves one node instance running. I noticed if I run from a cmd window instead it ends both processes correctly, but it would be much preferable for me to run from cygwin.
Same here on Linux Ubuntu 16.04 in (cluster mode) when i do Ctrl-C
I'm seeing the same on OSX, just started recently and don't have a clear repro.ctrl+c to kill the process, but sometimes it's lingering in the background. Specifically, I'm watching files and when I change them via other scripts, all of a sudden my rebuild process kicks off because the nodemon background process sees the changes. Took me a bit to understand what was happening, though I'm still not clear on why.
v 1.11.0 on OSX 10.12.1 Sierra.
I've experienced this for a while. Sometimes I end up with 10-20 node.exe and cmd.exe processes in my process list that I have to kill manually.
the same issue here 🙁
I can reliably reproduce this:
First up, in the code we're monitoring, bind to a TCP port, and bind to the SIGUSR2 signal:
process.on('SIGUSR2', () => { })
Second, create a .nodemon file to use a different process signal (we're using SIGUSR2):
{
"signal": "SIGHUP"
}
Third, start nodemon and kick it into the background:
nodemon --config ./nodemon.json --watch . server.js &
From this point, here's the process tree:
$ ps
PID USER TIME COMMAND
1 root 0:00 sh
6 root 0:00 node /usr/bin/nodemon --config ./nodemon.json --watch . serv
20 root 0:00 sh -c node server.js
21 root 0:00 node server.js
Modify a file, let nodemon restart things, you'll get an error about trying to bind to TCP we're using, the new process will die and it'll sit waiting for changes before it brings up another process.
Viewing the process tree at this point shows we successfully killed PID 20, but it didn't propagate to PID 21, which is our NodeJS process:
$ ps
PID USER TIME COMMAND
1 root 0:00 sh
6 root 0:00 node /usr/bin/nodemon --config ./nodemon.json --watch . serv
21 root 0:00 node server.js
I'm guessing there are some edge cases whereby nodemon deviates from the .nodemon config?
I found my issue above - my container didn't contain the nodemon.json config file. Adding the file to the container fixed the issue.
how do you kill nodemon when it wont shut off?
Same here. When I Ctrl+C or get an error on node, it leaves a process running when it's stopped on console. So I have to kill it manually every time.
How can we resolve this issue?
Here's my workaround:
Setup
npm uninstall -g nodemon
npm install -g pm2
Workflow
pm2 start --watch . --name=my-process index.js
pm2 logs my-process
Works great. Problem solved.
@andyfleming thanks! that's nice option (y)
I can't believe this is still not fixed.
@DiegoRBaquero happy to look at tests and a PR to merge if you can point me in its direction.
@remy Glancing at the code (and literally a 5-second glance) I see you have spawn.js and call child_process.spawn.
This is fine for non-node executables, but when running a node child process specifically, fork should be used. You get the benefits of IPC as well as automatic garbage collection when the parent dies.
I would suggest having a switch to use child_process.fork whenever a .js file is being run, or when the executable is node.
@remy here's my PR to fix the issue:
https://github.com/remy/nodemon/pull/1134
I'm guessing you'll edit it to be more consistent with the rest of the script but the concept is there, and I no longer get an Error [ERR_IPC_CHANNEL_CLOSED]: channel closed when the parent process dies because node automatically handles cleanup of forked child processes.
You might also need to do some work with the stdout/stderr, since in my code the child process is just using whatever fork defaults to.. like [0, 1, 2, 'ipc'] or something.
But hopefully this is the direction you were looking for :]
@heisian I need to revert this change for [email protected] but it'll go in as part of [email protected] - because it doesn't work with node@4 (in tests/config/env.js), but I'm dropping support for node@4 in nodemon@2 (I accidentally did it in 1.12.3 but it _should_ have been a major bump).
All live in latest nodemon (in [email protected] - I pushed a workaround for node@4 which uses spawn).
@remy Okay. Looking at the child_process.fork history, the stdio option was only introduced in v6.4.0, so that may be the reason.
Also command below works fine;
pm2 start npm --watch --name=myapp -- start
pm2 logs myapp
@angularturk that's a completely different module and doesn't provide any utility to this thread.
Most helpful comment
Here's my workaround:
Setup
Workflow
Works great. Problem solved.