fix: gitlab-workhorse graceful termination
All threads resolved!
All threads resolved!
Compare changes
Files
3-
What --- Move `gitlab-workhorse` process to PID 1. Why --- GitLab-workhorse supports [graceful termination](gitlab-org/gitlab#325114), however, we are not [using it](https://gitlab.com/gitlab-com/gl-infra/reliability/-/issues/15497#note_911366252), this causes the `gitlab-workhorse` pod to run for `30s` on shutdown responding with `502` and then receiving `SIGKILL`. By default Kubernetes sends `SIGTERM` to PID `1` in the container, and workhorse [listens for this signal](https://gitlab.com/gitlab-org/gitlab/-/blob/dbeafad46dda53092c0eb46eceb2337a83f3ee9c/workhorse/main.go#L242) however workhorse is not `PID` 1 as seen in the process tree below, this is because of 2 reasons: 1. `CMD` isn't passed as an array. https://docs.docker.com/engine/reference/builder/#cmd in it specifies: `CMD command param1 param2 (shell form)` so this sets `sh` as PID 1. 1. A shell script is [invoked](https://gitlab.com/gitlab-org/build/CNG/-/blob/92d3e22e9ff6c5cbb685aeea99813751d5e19a9d/gitlab-workhorse/Dockerfile#L51) which creates `gitlab-workhorse` as a child process. Process tree before: ``` git@gitlab-webservice-default-5d85b6854c-sbx2z:/$ ps faux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1015 0.0 0.0 805036 4588 ? Rsl 13:12 0:00 runc init git 1005 0.3 0.0 5992 3784 pts/0 Ss 13:12 0:00 bash git 1014 0.0 0.0 8592 3364 pts/0 R+ 13:12 0:00 \_ ps faux git 1 0.0 0.0 2420 532 ? Ss 12:52 0:00 /bin/sh -c /scripts/start-workhorse git 16 0.0 0.0 5728 3408 ? S 12:52 0:00 /bin/bash /scripts/start-workhorse git 19 0.0 0.3 1328480 33080 ? Sl 12:52 0:00 \_ gitlab-workhorse -logFile stdout -logFormat json -listenAddr 0.0.0.0:8181 -documentRoot /srv/gitlab/public -secretPath /etc/gitlab/gitlab-workhorse/secret -config /srv/gitlab/config/workhorse-config.toml ``` Process tree after: ``` git@gitlab-webservice-default-84c68fc9c9-dzfd4:/$ ps faux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND git 103 0.5 0.0 5992 3812 pts/0 Ss 07:33 0:00 bash git 111 0.0 0.0 8592 3172 pts/0 R+ 07:33 0:00 \_ ps faux git 1 0.1 0.3 1254496 32120 ? Ssl 07:32 0:00 gitlab-workhorse -logFile stdout -logFormat json -listenAddr 0.0.0.0:8181 -documentRoot /srv/gitlab/public -secretPath /etc/gitlab/gitlab-workhorse/secret -config /srv/gitlab/config/workhorse-config.toml ``` reference https://gitlab.com/gitlab-com/gl-infra/reliability/-/issues/15497 Signed-off-by:
Steve Azzopardi <sazzopardi@gitlab.com>
@@ -14,7 +14,7 @@ if [[ "${GITLAB_WORKHORSE_PROM_LISTEN_ADDR}" =~ ^.+:[0-9][0-9]{0,4}$ ]]; then