Skip to content

Commit

Permalink
split SIGCHLD from all other signal handlers in supervisor (v2) (#492)
Browse files Browse the repository at this point in the history
* split SIGCHLD from all other signal handlers in supervisor

* give a fuzzier window for test_tasks
  • Loading branch information
tgross authored Aug 22, 2017
1 parent c2e2525 commit 19f43a5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
4 changes: 2 additions & 2 deletions integration_tests/tests/test_tasks/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ TASK1_TOS=$(cat ${APP_ID}.log | grep "\[task1\] timeout" | wc -l | tr -d '[[:spa
TASK1_RUNS=$(cat ${APP_ID}.task1 | wc -l | tr -d '[[:space:]]')
rm ${APP_ID}.task1

if [[ $TASK1_RUNS -lt 7 || $TASK1_RUNS -gt 8 ]]; then
echo "Expected task1 to have 7 or 8 executions: got $TASK1_RUNS"
if [[ $TASK1_RUNS -lt 5 || $TASK1_RUNS -gt 8 ]]; then
echo "Expected task1 to >5 and <8 executions: got $TASK1_RUNS"
PASS=1
fi
if [ $TASK1_TOS -gt 0 ]; then
Expand Down
30 changes: 21 additions & 9 deletions sup/sup.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@ func Run() {
if err != nil {
log.Fatal("failed to start ContainerPilot worker process:", err)
}
handleSignals(proc.Pid)
passThroughSignals(proc.Pid)
handleReaping(proc.Pid)
proc.Wait()
}

// handleSignals listens for signals used to gracefully shutdown and
// passThroughSignals listens for signals used to gracefully shutdown and
// passes them thru to the ContainerPilot worker process.
func handleSignals(pid int) {
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGINT, syscall.SIGCHLD, syscall.SIGUSR1)
func passThroughSignals(pid int) {
sigRecv := make(chan os.Signal, 1)
signal.Notify(sigRecv, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGINT, syscall.SIGUSR1)
go func() {
for signal := range sig {
switch signal {
for sig := range sigRecv {
switch sig {
case syscall.SIGINT:
syscall.Kill(pid, syscall.SIGINT)
case syscall.SIGTERM:
Expand All @@ -41,13 +42,24 @@ func handleSignals(pid int) {
syscall.Kill(pid, syscall.SIGHUP)
case syscall.SIGUSR1:
syscall.Kill(pid, syscall.SIGUSR1)
case syscall.SIGCHLD:
go reap()
}
}
}()
}

// handleReaping listens for the SIGCHLD signal only and triggers
// reaping of child processes
func handleReaping(pid int) {
sigRecv := make(chan os.Signal, 1)
signal.Notify(sigRecv, syscall.SIGCHLD)
go func() {
for {
<-sigRecv
reap()
}
}()
}

// reaps child processes that have been reparented to PID1
func reap() {
for {
Expand Down

0 comments on commit 19f43a5

Please sign in to comment.