@@ -22,8 +22,8 @@ import (
22
22
"github.com/gitpod-io/gitpod/common-go/process"
23
23
"github.com/gitpod-io/gitpod/supervisor/pkg/shared"
24
24
"github.com/gitpod-io/gitpod/supervisor/pkg/supervisor"
25
+ reaper "github.com/gitpod-io/go-reaper"
25
26
"github.com/prometheus/procfs"
26
- reaper "github.com/ramr/go-reaper"
27
27
"github.com/spf13/cobra"
28
28
)
29
29
@@ -77,25 +77,55 @@ var initCmd = &cobra.Command{
77
77
}
78
78
79
79
supervisorDone := make (chan struct {})
80
+ handledByReaper := make (chan int )
81
+ handleSupervisorExit := func (exitCode int ) {
82
+ if exitCode == 0 {
83
+ return
84
+ }
85
+ logs := extractFailureFromRun ()
86
+ if shared .IsExpectedShutdown (exitCode ) {
87
+ log .Fatal (logs )
88
+ } else {
89
+ log .WithError (fmt .Errorf (logs )).Fatal ("supervisor run error with unexpected exit code" )
90
+ }
91
+ }
80
92
go func () {
81
93
defer close (supervisorDone )
82
94
83
95
err := runCommand .Wait ()
84
- if err != nil && ! (strings .Contains (err .Error (), "signal: " ) || strings .Contains (err .Error (), "no child processes" )) {
96
+ if err == nil {
97
+ return
98
+ }
99
+ // exited by reaper
100
+ if strings .Contains (err .Error (), "no child processes" ) {
101
+ ctx , cancel := context .WithTimeout (context .Background (), time .Second * 5 )
102
+ defer cancel ()
103
+ select {
104
+ case <- ctx .Done (): // timeout
105
+ case exitCode := <- handledByReaper :
106
+ handleSupervisorExit (exitCode )
107
+ }
108
+ } else if ! (strings .Contains (err .Error (), "signal: " )) {
85
109
if eerr , ok := err .(* exec.ExitError ); ok && eerr .ExitCode () != 0 {
86
- logs := extractFailureFromRun ()
87
- if shared .IsExpectedShutdown (eerr .ExitCode ()) {
88
- log .Fatal (logs )
89
- } else {
90
- log .WithError (fmt .Errorf (logs )).Fatal ("supervisor run error with unexpected exit code" )
91
- }
110
+ handleSupervisorExit (eerr .ExitCode ())
92
111
}
93
112
log .WithError (err ).Error ("supervisor run error" )
94
113
return
95
114
}
96
115
}()
97
116
// start the reaper to clean up zombie processes
98
- reaper .Reap ()
117
+ reaper .Start (reaper.Config {
118
+ Pid : - 1 ,
119
+ Options : 0 ,
120
+ DisablePid1Check : false ,
121
+ OnReap : func (pid int , wstatus syscall.WaitStatus ) {
122
+ if pid != runCommand .Process .Pid {
123
+ return
124
+ }
125
+ exitCode := wstatus .ExitStatus ()
126
+ handledByReaper <- exitCode
127
+ },
128
+ })
99
129
100
130
select {
101
131
case <- supervisorDone :
0 commit comments