Skip to content

Commit 8f90ca8

Browse files
committed
Improve reaper racing
1 parent be4bda0 commit 8f90ca8

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

components/supervisor/cmd/init.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import (
2222
"github.com/gitpod-io/gitpod/common-go/process"
2323
"github.com/gitpod-io/gitpod/supervisor/pkg/shared"
2424
"github.com/gitpod-io/gitpod/supervisor/pkg/supervisor"
25+
reaper "github.com/gitpod-io/go-reaper"
2526
"github.com/prometheus/procfs"
26-
reaper "github.com/ramr/go-reaper"
2727
"github.com/spf13/cobra"
2828
)
2929

@@ -77,25 +77,39 @@ var initCmd = &cobra.Command{
7777
}
7878

7979
supervisorDone := make(chan struct{})
80+
handleSupervisorExit := func(exitCode int) {
81+
logs := extractFailureFromRun()
82+
if shared.IsExpectedShutdown(exitCode) {
83+
log.Fatal(logs)
84+
} else {
85+
log.WithError(fmt.Errorf(logs)).Fatal("supervisor run error with unexpected exit code")
86+
}
87+
}
8088
go func() {
8189
defer close(supervisorDone)
8290

8391
err := runCommand.Wait()
8492
if err != nil && !(strings.Contains(err.Error(), "signal: ") || strings.Contains(err.Error(), "no child processes")) {
8593
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-
}
94+
handleSupervisorExit(eerr.ExitCode())
9295
}
9396
log.WithError(err).Error("supervisor run error")
9497
return
9598
}
9699
}()
97100
// start the reaper to clean up zombie processes
98-
reaper.Reap()
101+
reaper.Start(reaper.Config{
102+
Pid: -1,
103+
Options: 0,
104+
DisablePid1Check: false,
105+
OnReap: func(pid int, wstatus syscall.WaitStatus) {
106+
if pid != runCommand.Process.Pid {
107+
return
108+
}
109+
exitCode := wstatus.ExitStatus()
110+
handleSupervisorExit(exitCode)
111+
},
112+
})
99113

100114
select {
101115
case <-supervisorDone:

components/supervisor/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ require (
1616
github.com/gitpod-io/gitpod/ide-metrics-api v0.0.0-00010101000000-000000000000
1717
github.com/gitpod-io/gitpod/supervisor/api v0.0.0-00010101000000-000000000000
1818
github.com/gitpod-io/gitpod/ws-daemon/api v0.0.0-00010101000000-000000000000
19+
github.com/gitpod-io/go-reaper v0.0.0-20241023132555-bf7fe3193e95
1920
github.com/golang/mock v1.6.0
2021
github.com/google/go-cmp v0.6.0
2122
github.com/google/uuid v1.6.0
@@ -29,7 +30,6 @@ require (
2930
github.com/prometheus/common v0.42.0
3031
github.com/prometheus/procfs v0.10.1
3132
github.com/prometheus/pushgateway v1.5.1
32-
github.com/ramr/go-reaper v0.2.1
3333
github.com/sirupsen/logrus v1.9.3
3434
github.com/soheilhy/cmux v0.1.5
3535
github.com/spf13/cobra v1.4.0

components/supervisor/go.sum

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)