Skip to content

gitaly: Shorten maximum internal socket path length

With the migration to the new runtime directory, Gitaly has moved its internal socket directory as well. Unfortunately, this change resulted in an expansion of the internal socket path length, and because Unix systems put a limit on Unix socket paths this has caused Gitaly to not come up on some systems anymore.

This problem is entirely fixable by the administrator by configuring a different runtime directory path that has a shorter prefix. But we can at least try to shorten the paths we generate a bit. Right now, Gitaly creates three different types of internal sockets:

- The internal socket that is used e.g. by `gitaly-hooks` to connect
  back to Gitaly. This file is created as `internal_${PID}.sock`.
  Including the PID is not required anymore though: the runtime
  directory always contains `gitaly-${PID}` anyway. So we can easily
  shorten this to just `intern`. This leaves us with a socket name
  length of 6.

- The Ruby worker sockets, which are created as `ruby.$N`. `$N` is
  the number of any worker, and typically shouldn't be larger than
  in the tens. This leaves us with a typical socket name length of
  7.

- The internal test socket that is created to verify whether we can
  create and connect to internal sockets. This is done as a sanity
  check to alert administrators early on in case the socket path
  length exceeds the system's limits. Right now it's created as
  `test-XXXX.sock`, but given that we're about to change the naming
  strategy we must only ensure that it's as long as the longest
  socket we're creating. Furthermore, we don't need to create it
  with a random part anymore given that the runtime directory is
  keyed by PID. We thus use `tsocket`, which has a socket name
  length of 7.

With these changes in place we reduce the maximum socket name length from 19 characters to 7 characters, which gives us administrators 12 characters more room to play with.

Related to gitlab-development-kit#1480 (closed).

Merge request reports