saltstack/salt — pull request #15194 by dmick (2014-08-22 19:51:02+00:00)
Title: sigterm_clean: just return if not master

Daemon shutdown with SIGTERM had a race where child processes could be
left orphaned. The problem was that the signal was delivered to the
master, but then the master would call multiprocess.Process.terminate(),
which would send SIGTERM to the child as well; since the child had the
same data in its Master object, it would also try to go kill all the
child processes, and chaos ensued.

I'd like to have stopped the children from having this sigterm handler
installed by installing it after starting the children, but they are
started inside ReqServer.run(), which doesn't return.

I'd also like to see the SIGTERM handler just set a global flag and poll
that flag in the main loop (doing anything inside the signal handler at
all is dangerous). But the main loop is inside zmq.device() (which is,
btw, deprecated since libzmq 3.0), and I don't know if there's a zmq
transformation that would allow control to return to the main thread
periodically.

Another possible option is to reset the signal handler in each child's
Process() target function; that also seems to work, but touches more
code and files.

Fixes: #12248
Signed-off-by: Dan Mick