-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[supervisor] set pod failure reason when supervisor is reaped #20318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,8 +22,8 @@ import ( | |
"github.com/gitpod-io/gitpod/common-go/process" | ||
"github.com/gitpod-io/gitpod/supervisor/pkg/shared" | ||
"github.com/gitpod-io/gitpod/supervisor/pkg/supervisor" | ||
reaper "github.com/gitpod-io/go-reaper" | ||
"github.com/prometheus/procfs" | ||
reaper "github.com/ramr/go-reaper" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
|
@@ -77,25 +77,55 @@ var initCmd = &cobra.Command{ | |
} | ||
|
||
supervisorDone := make(chan struct{}) | ||
handledByReaper := make(chan int) | ||
handleSupervisorExit := func(exitCode int) { | ||
if exitCode == 0 { | ||
return | ||
} | ||
logs := extractFailureFromRun() | ||
if shared.IsExpectedShutdown(exitCode) { | ||
log.Fatal(logs) | ||
} else { | ||
log.WithError(fmt.Errorf(logs)).Fatal("supervisor run error with unexpected exit code") | ||
} | ||
} | ||
go func() { | ||
defer close(supervisorDone) | ||
|
||
err := runCommand.Wait() | ||
if err != nil && !(strings.Contains(err.Error(), "signal: ") || strings.Contains(err.Error(), "no child processes")) { | ||
if err == nil { | ||
return | ||
} | ||
// exited by reaper | ||
if strings.Contains(err.Error(), "no child processes") { | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) | ||
defer cancel() | ||
select { | ||
case <-ctx.Done(): // timeout | ||
case exitCode := <-handledByReaper: | ||
handleSupervisorExit(exitCode) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sweet! |
||
} | ||
} else if !(strings.Contains(err.Error(), "signal: ")) { | ||
if eerr, ok := err.(*exec.ExitError); ok && eerr.ExitCode() != 0 { | ||
logs := extractFailureFromRun() | ||
if shared.IsExpectedShutdown(eerr.ExitCode()) { | ||
log.Fatal(logs) | ||
} else { | ||
log.WithError(fmt.Errorf(logs)).Fatal("supervisor run error with unexpected exit code") | ||
} | ||
handleSupervisorExit(eerr.ExitCode()) | ||
} | ||
log.WithError(err).Error("supervisor run error") | ||
return | ||
} | ||
}() | ||
// start the reaper to clean up zombie processes | ||
reaper.Reap() | ||
reaper.Start(reaper.Config{ | ||
Pid: -1, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this config mean? Would it make sense to add a comment for that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This config comes from default |
||
Options: 0, | ||
DisablePid1Check: false, | ||
OnReap: func(pid int, wstatus syscall.WaitStatus) { | ||
if pid != runCommand.Process.Pid { | ||
geropl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return | ||
} | ||
exitCode := wstatus.ExitStatus() | ||
handledByReaper <- exitCode | ||
}, | ||
}) | ||
|
||
select { | ||
case <-supervisorDone: | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.