Skip to content

Commit 19f43a5

Browse files
authored
split SIGCHLD from all other signal handlers in supervisor (v2) (#492)
* split SIGCHLD from all other signal handlers in supervisor * give a fuzzier window for test_tasks
1 parent c2e2525 commit 19f43a5

2 files changed

Lines changed: 23 additions & 11 deletions

File tree

integration_tests/tests/test_tasks/run.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ TASK1_TOS=$(cat ${APP_ID}.log | grep "\[task1\] timeout" | wc -l | tr -d '[[:spa
2424
TASK1_RUNS=$(cat ${APP_ID}.task1 | wc -l | tr -d '[[:space:]]')
2525
rm ${APP_ID}.task1
2626

27-
if [[ $TASK1_RUNS -lt 7 || $TASK1_RUNS -gt 8 ]]; then
28-
echo "Expected task1 to have 7 or 8 executions: got $TASK1_RUNS"
27+
if [[ $TASK1_RUNS -lt 5 || $TASK1_RUNS -gt 8 ]]; then
28+
echo "Expected task1 to >5 and <8 executions: got $TASK1_RUNS"
2929
PASS=1
3030
fi
3131
if [ $TASK1_TOS -gt 0 ]; then

sup/sup.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,19 @@ func Run() {
2121
if err != nil {
2222
log.Fatal("failed to start ContainerPilot worker process:", err)
2323
}
24-
handleSignals(proc.Pid)
24+
passThroughSignals(proc.Pid)
25+
handleReaping(proc.Pid)
2526
proc.Wait()
2627
}
2728

28-
// handleSignals listens for signals used to gracefully shutdown and
29+
// passThroughSignals listens for signals used to gracefully shutdown and
2930
// passes them thru to the ContainerPilot worker process.
30-
func handleSignals(pid int) {
31-
sig := make(chan os.Signal, 1)
32-
signal.Notify(sig, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGINT, syscall.SIGCHLD, syscall.SIGUSR1)
31+
func passThroughSignals(pid int) {
32+
sigRecv := make(chan os.Signal, 1)
33+
signal.Notify(sigRecv, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGINT, syscall.SIGUSR1)
3334
go func() {
34-
for signal := range sig {
35-
switch signal {
35+
for sig := range sigRecv {
36+
switch sig {
3637
case syscall.SIGINT:
3738
syscall.Kill(pid, syscall.SIGINT)
3839
case syscall.SIGTERM:
@@ -41,13 +42,24 @@ func handleSignals(pid int) {
4142
syscall.Kill(pid, syscall.SIGHUP)
4243
case syscall.SIGUSR1:
4344
syscall.Kill(pid, syscall.SIGUSR1)
44-
case syscall.SIGCHLD:
45-
go reap()
4645
}
4746
}
4847
}()
4948
}
5049

50+
// handleReaping listens for the SIGCHLD signal only and triggers
51+
// reaping of child processes
52+
func handleReaping(pid int) {
53+
sigRecv := make(chan os.Signal, 1)
54+
signal.Notify(sigRecv, syscall.SIGCHLD)
55+
go func() {
56+
for {
57+
<-sigRecv
58+
reap()
59+
}
60+
}()
61+
}
62+
5163
// reaps child processes that have been reparented to PID1
5264
func reap() {
5365
for {

0 commit comments

Comments
 (0)