Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorMateusz Nowotyński <maxmati4@gmail.com>2020-02-12 22:46:03 +0300
committerMateusz Nowotyński <maxmati4@gmail.com>2020-02-26 00:49:55 +0300
commitba3d562bff44ee9becaee13e1d89bee36855144d (patch)
tree34ddfc8b35e3763a4a59c33778705a8c8d7214c1 /cmd
parent52e06c2e6eb2d3ba6f4fdd5b48ce3a52043558a8 (diff)
Handle malformed PID file in gitaly-wrapper
When the gitaly PID file is malformed log warning and ignore it. Malformed the file will be overwritten when the new gitaly process starts. relates #2453 Signed-off-by: Mateusz Nowotyński <maxmati4@gmail.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/gitaly-wrapper/main.go11
-rw-r--r--cmd/gitaly-wrapper/main_test.go34
2 files changed, 43 insertions, 2 deletions
diff --git a/cmd/gitaly-wrapper/main.go b/cmd/gitaly-wrapper/main.go
index ec0d2c522..20d491058 100644
--- a/cmd/gitaly-wrapper/main.go
+++ b/cmd/gitaly-wrapper/main.go
@@ -40,8 +40,10 @@ func main() {
log.WithField("pid_file", pidFile()).Info("finding gitaly")
gitaly, err := findGitaly()
- if err != nil {
+ if err != nil && !isRecoverable(err) {
log.WithError(err).Fatal("find gitaly")
+ } else if err != nil {
+ log.WithError(err).Error("find gitaly")
}
if gitaly != nil && isGitaly(gitaly, gitalyBin) {
@@ -70,9 +72,14 @@ func main() {
log.Error("wrapper for gitaly shutting down")
}
+func isRecoverable(err error) bool {
+ _, isNumError := err.(*strconv.NumError)
+ return os.IsNotExist(err) || isNumError
+}
+
func findGitaly() (*os.Process, error) {
pid, err := getPid()
- if err != nil && !os.IsNotExist(err) {
+ if err != nil {
return nil, err
}
diff --git a/cmd/gitaly-wrapper/main_test.go b/cmd/gitaly-wrapper/main_test.go
index 2b5778142..59963da52 100644
--- a/cmd/gitaly-wrapper/main_test.go
+++ b/cmd/gitaly-wrapper/main_test.go
@@ -1,6 +1,7 @@
package main
import (
+ "errors"
"io/ioutil"
"os"
"os/exec"
@@ -44,3 +45,36 @@ func TestStolenPid(t *testing.T) {
require.True(t, isGitaly(tail, "/path/to/tail"))
})
}
+
+func TestIsRecoverable(t *testing.T) {
+ _, numericError := strconv.Atoi("")
+
+ tests := []struct {
+ name string
+ err error
+ want bool
+ }{
+ {
+ name: "file doesn't exist",
+ err: os.ErrNotExist,
+ want: true,
+ },
+ {
+ name: "numeric error",
+ err: numericError,
+ want: true,
+ },
+ {
+ name: "generic error",
+ err: errors.New("generic error"),
+ want: false,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := isRecoverable(tt.err); got != tt.want {
+ t.Errorf("isRecoverable() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}