diff --git a/integration_tests/tests/test_tasks/run.sh b/integration_tests/tests/test_tasks/run.sh index 6784d660..e1797494 100755 --- a/integration_tests/tests/test_tasks/run.sh +++ b/integration_tests/tests/test_tasks/run.sh @@ -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 diff --git a/sup/sup.go b/sup/sup.go index 5ca0d8c0..ddeffdaa 100644 --- a/sup/sup.go +++ b/sup/sup.go @@ -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: @@ -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 {