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
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-05-06 09:29:58 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-05-06 11:43:57 +0300
commit3fcda892967769fbcb0b2f6ced3fba0641a57d4d (patch)
tree2be71ceb0da9aaa342de67ceb5c24d3510323a7e
parent75db0aacda6a2db06bfe221aaffb2aadf4846118 (diff)
config: Improve error message when test socket creation failspks-gitaly-config-improve-error-with-too-long-sockets
When Gitaly starts up, it will verify that it can indeed create Unix sockets in its runtime directory. This check is required because Unix systems have strict limits on Unix socket path lengths due to `struct sockaddr_un`'s `sun_path` is a capped character array. On macOS this limit is at 104 characters, while Linux has a limit of 108 characters, both of which are easy to exceed. But while we do have these sanity checks in place, the error message we return is really hard for an administrator to interpret because all it talks about is an `invalid argument` passed to bind(3P). So ultimately, the administrator likely won't make the connection between the runtime directory being too long and an `invalid argument`. Improve this error message by catching EINVAL returned by `net.Listen()` and providing a readable error message that explicitly tells the admin that the issue is most likely that the path is too long and that the runtime directory should be changed.
-rw-r--r--internal/gitaly/config/config.go8
-rw-r--r--internal/gitaly/config/config_test.go10
2 files changed, 8 insertions, 10 deletions
diff --git a/internal/gitaly/config/config.go b/internal/gitaly/config/config.go
index 8ed64b565..505a0fb9d 100644
--- a/internal/gitaly/config/config.go
+++ b/internal/gitaly/config/config.go
@@ -9,6 +9,7 @@ import (
"path/filepath"
"reflect"
"strings"
+ "syscall"
"time"
"github.com/pelletier/go-toml"
@@ -499,7 +500,12 @@ func trySocketCreation(dir string) error {
// Attempt to create an actual socket and not just a file to catch socket path length problems
l, err := net.Listen("unix", socketPath)
if err != nil {
- return fmt.Errorf("socket could not be created in %s: %s", dir, err)
+ var errno syscall.Errno
+ if errors.As(err, &errno) && errno == syscall.EINVAL {
+ return fmt.Errorf("%w: your socket path is likely too long, please change Gitaly's runtime directory", errno)
+ }
+
+ return fmt.Errorf("socket could not be created in %s: %w", dir, err)
}
return l.Close()
diff --git a/internal/gitaly/config/config_test.go b/internal/gitaly/config/config_test.go
index d683fa352..bbb348e60 100644
--- a/internal/gitaly/config/config_test.go
+++ b/internal/gitaly/config/config_test.go
@@ -677,15 +677,7 @@ func TestValidateInternalSocketDir(t *testing.T) {
return runtimeDirTooLongForSockets
},
verify: func(t *testing.T, runtimeDir string, actualErr error) {
- require.Error(t, actualErr)
- require.Regexp(t,
- fmt.Sprintf(
- "failed creating internal test socket: socket could not be created in %s: listen unix %s: bind: invalid argument",
- filepath.Join(runtimeDir, "sock\\.d"),
- filepath.Join(runtimeDir, "sock\\.d", "tsocket"),
- ),
- actualErr.Error(),
- )
+ require.EqualError(t, actualErr, "failed creating internal test socket: invalid argument: your socket path is likely too long, please change Gitaly's runtime directory")
},
},
}