Nodemon: Nodemon SIGINT event handler conflicts with Yarn

Created on 30 Apr 2018  路  4Comments  路  Source: remy/nodemon

package.json:

{
  ...
  "scripts": {
    "start": "node start.js"
  }
}

start.js:

require('nodemon');
setTimeout(() => {}, 1e6);

In the terminal:

# Does not print anything (except `grep` itself), i.e. no node process is running
$ ps aux | grep node
# We run the `start` task then interrupt it with CTRL-C
$ yarn start
yarn run v1.6.0
node start.js
^C
# yarn was killed, but not `start.js`
$ ps aux | grep node
me     4053  0.0  0.0   4608   876 pts/2    S    14:29   0:00 /bin/sh -c node start.js
me     4054  0.0  0.0 873592 28564 pts/2    Sl   14:29   0:00 node start.js

Without the require('nodemon') line, the start.js process would be properly killed by yarn.

Note that this is not a problem with npm run. It might be related (not sure) to https://github.com/yarnpkg/yarn/issues/4667. The reason I submit an issue on Nodemon is that I think this might be a problem with Nodemon not Yarn.

When being required, Nodemon installs a SIGINT event handler. When yarn gets a CTRL-C, it forwards it to script.js but this is a noop because SIGINT has an event handler.

The example is a bit contrived in order to pinpoint the problem, but in a real life scenario:

  • instead of setTimeout() I have gulp.watch()
  • Nodemon is being required but is only run with specific Gulp tasks
  • this results in my Gulp watch tasks not to exit on CTRL-C when Gulp is run through Yarn

One workaround is to conditionally require Nodemon only when I am going to instantiate it, but this feels more like a hack than a real solution.

Versions: Node.js 8.11.0, Nodemon 1.17.3, yarn 1.6.0, Ubuntu 17.10

bug has PR

All 4 comments

It _is_ yarn, I'm able to replicate with yarn, but not with npm:

screen shot 2018-04-30 at 14 51 02

_but_ it's also something I can fix inside of nodemon too. Hang tight.

Yes the PR seems to directly fix this problem! Thanks a lot, that was fast!

@ehmicky not particularly fast, just lucky to have some down time before I have to make my kids their dinner.

@remy Not sure if it's perhaps another issue, but I still seem to be running into this.
When I run a process with nodemon directly, no problems. When I run it with yarn, no problem. When I combine yarn and nodemon, I can never get the process to exit, having to press CTRL-C twice.

I have created an SO question with more details here: https://superuser.com/questions/1594660/why-does-zsh-keep-running-after-exiting-a-process-with-ctrl-c-until-ctrl-c-is-p

See also https://github.com/remy/nodemon/issues/1647, that's exactly what I'm running into.

Was this page helpful?
0 / 5 - 0 ratings