Skip to content

pm2 now kills detached processes (as of 0.12.2) #1036

@ryanbmilbourne

Description

@ryanbmilbourne

I have pm2 managing a node daemon that spawns worker processes as detached children. The idea was that if the daemon was killed or restarted (after an upgrade, for example) the workers would continue working and publishing to the pub/sub system they work with. After upgrading to the latest version from 0.10.x, I noticed that pm2 was killing my detached workers as well as the daemon it was managing.

It looks to me like this is directly related to the addition of the new TreeKill system (fe92e71) in 0.12.2. See lines 69-70 of TreeKill:

  var args = downgradePs ? '-eo pid,ppid | grep -w ' : '-o pid --no-headers --ppid ';
  var ps = exec('ps ' + args + ppid, function(err, stdout, stderr){...}

That ps command will return the list of all children with that ppid, which, unfortunately, includes children that are detached so that they can live beyond the death of the parent that spawned them. Rather than sending a signal to the parent and relying on it to clean up the children, it looks like pm2 is now sending SIGTERM to all processes in the tree.

Would there be support for an option or config to have pm2 kill processes in the older manner as opposed to this new(er) KillTree method? It seems to me like there'd be support to kill the parent and have it clean up its children as it sees fit rather than use the nuclear option.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions