diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-03-15 12:33:18 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-03-24 16:52:49 +0300 |
commit | 7b5acbe6ed71a017d9075df9b25ab58044476b98 (patch) | |
tree | c9de09bb0a7200a1b641277ad9b6d6caeac3f3a7 | |
parent | 3bf444a62ad3ca73c44019480f0144caf1e96fee (diff) |
cmd/gitaly-wrapper: Log warning when supervised command fails
We currently ignore any errors when waiting for the supervised command
fails. Log the error so that we at least have a chance to see that
something may have gone wrong.
-rw-r--r-- | .golangci.yml | 4 | ||||
-rw-r--r-- | cmd/gitaly-wrapper/main.go | 10 |
2 files changed, 7 insertions, 7 deletions
diff --git a/.golangci.yml b/.golangci.yml index b1359a125..226847520 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -79,10 +79,6 @@ issues: text: "Error return value of `[^`]+.(Close|Serve)` is not checked" - linters: - errcheck - path: "cmd/gitaly-wrapper/main.go" - text: "Error return value of `cmd.Wait` is not checked" - - linters: - - errcheck path: "internal/praefect/nodes/local_elector.go" text: "Error return value of `s.checkNodes` is not checked" - linters: diff --git a/cmd/gitaly-wrapper/main.go b/cmd/gitaly-wrapper/main.go index 247b71f2d..2ce2037c4 100644 --- a/cmd/gitaly-wrapper/main.go +++ b/cmd/gitaly-wrapper/main.go @@ -58,7 +58,7 @@ func main() { } else { logger.Info("spawning a process") - proc, err := spawnProcess(binary, arguments) + proc, err := spawnProcess(logger, binary, arguments) if err != nil { logger.WithError(err).Fatal("spawn gitaly") } @@ -103,7 +103,7 @@ func findProcess(pidFilePath string) (*os.Process, error) { return nil, nil } -func spawnProcess(bin string, args []string) (*os.Process, error) { +func spawnProcess(logger *logrus.Entry, bin string, args []string) (*os.Process, error) { cmd := exec.Command(bin, args...) cmd.Env = append(os.Environ(), fmt.Sprintf("%s=true", bootstrap.EnvUpgradesEnabled)) @@ -116,7 +116,11 @@ func spawnProcess(bin string, args []string) (*os.Process, error) { } // This cmd.Wait() is crucial. Without it we cannot detect if the command we just spawned has crashed. - go cmd.Wait() + go func() { + if err := cmd.Wait(); err != nil { + logger.WithError(err).Error("waiting for supervised command") + } + }() return cmd.Process, nil } |