kmagiera / babel-watch

Reload your babel-node app on JS source file changes. And do it fast.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Process doesn't stop on SIGTERM

IMalyugin opened this issue · comments

I've been using babel-watch for ages and always had issues with zombie processes appearing from time to time. It wasn't a big deal, as I simply cleared all the "node" threads in the Activity Monitor. From my experience the problem was usually caused by crashed express server.

Anyways, the time has come for me to cover my configuration with unit testing and so that problem with hanging processes became super apparent, it simply hangs every launch when triggered by an external child_process call (execa included).

Spent whole day trying to terminate the process from outside - no use, even terminating whole tree of processes doesn't work. And then I finally started debugging the issue from inside of babel-watch.

The problem was rather apparent, there is no code for graceful SIGTERM handling. The only processes signal is SIGINT (which fires from ctrl+c). But if process closes during another signal, it just hangs and becomes a zombie. Popular libraries use signal-exit to cover all the possible termination reasons.

Got a pull request, waiting for your feedback :)

Will test all the listed cases today/tomorrow and remove Draft: prefix

Hey, great. This has been affecting us all for a long time and I've tried to fix it a few times. The PR looks good, happy to review & merge after you get a chance to test & try it.

Tried it out, tested, everything's working perfectly, not a single new node process despite me updating crashing, restarting - doing anything and everything :)

Got a check-list filled out in the pull request

To be entirely honest, there are still two use cases that hang:

  • SIGSTOP, fired by calling ctrl+z;
  • SIGKILL, there are no graceful ways to shut it;

It is possible to fix both:

  • SIGSTOP will hang any process it is meant to hang them, most just call it "by accident", but still.
  • SIGKILL, can't be stopped via hook, but we could close workers from inside if their parent is killed.