gitlab ログに「failed to receive response: dial unix /var/opt/gitlab/gitlab-rails/sockets/gitlab.socket: connect: connection refused」が発生した場合の対処法

gitlab ログに「failed to receive response: dial unix /var/opt/gitlab/gitlab-rails/sockets/gitlab.socket: connect: connection refused」が発生した場合の対処法

gitlabで、ログに「failed to receive response: dial unix /var/opt/gitlab/gitlab-rails/sockets/gitlab.socket: connect: connection refused」が発生した場合の対処法を記述してます。

環境

  • gitlab 15.4.1
  • OS Ubuntu 22.10

エラー全文

「502」が発生し利用できない状態になりました

# gitlab-ctl tail

==> /var/log/gitlab/node-exporter/current <==
2022-10-04_04:29:52.63481 ts=2022-10-04T04:29:52.634Z caller=collector.go:169 level=error msg="collector failed" name=powersupplyclass duration_seconds=0.034078473 err="could not get power_supply class info: error obtaining power_supply class info: failed to read file \"/sys/class/power_supply/BAT0/energy_full_design\": no such device"

==> /var/log/gitlab/gitlab-workhorse/current <==
{"correlation_id":"","duration_ms":0,"error":"badgateway: failed to receive response: dial unix /var/opt/gitlab/gitlab-rails/sockets/gitlab.socket: connect: connection refused","level":"error","method":"GET","msg":"","time":"2022-10-04T13:29:53+09:00","uri":""}

原因

ポート「8080」が別のサービスが利用していたため「puma」と重複していたことにより発生
※「8080」使用してるサービスは以下で確認できます。

$ sudo netstat -tulpn | grep 8080

対処法

自分の場合は「Jenkins」側のポート番号を変更しましたが「puma」のポート番号を変えても大丈夫です。

# nano /etc/gitlab/gitlab.rb

以下の箇所を使用してないポートに変更します。

※8082は「gitlab-prometheus」が使用しています。

# lsof -i:8082
COMMAND     PID              USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
prometheu 68193 gitlab-prometheus   58u  IPv4 287016      0t0  TCP localhost:38330->localhost:8082 (ESTABLISHED)
ruby      68237               git   11u  IPv4 286954      0t0  TCP localhost:8082 (LISTEN)
ruby      68237               git   14u  IPv4 286203      0t0  TCP localhost:8082->localhost:38330 (ESTABLISHED)

あとは、反映と再起動を行います。

# gitlab-ctl reconfigure
# gitlab-ctl restart