Skip to content

Commit 48b52ac

Browse files
committed
fixup: racing
1 parent 2ba9647 commit 48b52ac

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

components/supervisor/cmd/init.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ var initCmd = &cobra.Command{
7777
}
7878

7979
supervisorDone := make(chan struct{})
80+
handledByReaper := make(chan int)
8081
handleSupervisorExit := func(exitCode int) {
8182
logs := extractFailureFromRun()
8283
if shared.IsExpectedShutdown(exitCode) {
@@ -89,7 +90,19 @@ var initCmd = &cobra.Command{
8990
defer close(supervisorDone)
9091

9192
err := runCommand.Wait()
92-
if err != nil && !(strings.Contains(err.Error(), "signal: ") || strings.Contains(err.Error(), "no child processes")) {
93+
if err == nil {
94+
return
95+
}
96+
// exited by reaper
97+
if strings.Contains(err.Error(), "no child processes") {
98+
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
99+
defer cancel()
100+
select {
101+
case <-ctx.Done(): // timeout
102+
case exitCode := <-handledByReaper:
103+
handleSupervisorExit(exitCode)
104+
}
105+
} else if !(strings.Contains(err.Error(), "signal: ")) {
93106
if eerr, ok := err.(*exec.ExitError); ok && eerr.ExitCode() != 0 {
94107
handleSupervisorExit(eerr.ExitCode())
95108
}
@@ -107,7 +120,7 @@ var initCmd = &cobra.Command{
107120
return
108121
}
109122
exitCode := wstatus.ExitStatus()
110-
handleSupervisorExit(exitCode)
123+
handledByReaper <- exitCode
111124
},
112125
})
113126

0 commit comments

Comments
 (0)