dgtlcrur

はてなのリソースをちょっとだけ消費するチラシの裏

うちのインスタンスがしばらくすると502エラーになる件

引きこもりMastodon、なぜか起動してしばらくたつと"502 Bad Gateway"になってしまいます。

f:id:surdon:20171207100936p:plain

前回再起動時に事前に下記コマンドでdockerコンテナログを全部クリアしていたので、実質起動直後から今までのログが溜まっている状態です。

$ sudo truncate -s 0 /var/lib/docker/containers/*/*-json.log

web_1コンテナの最後のログが、

web_1 [10] ! Out-of-sync worker list, no 20 worker
web_1 [10] - Worker 0 (pid: 1361) booted, phase: 0

pumaがエラーになったあと再起動したようなログっぽく見える。(結果的に再起動できてないから502エラーになっている?)

docker-compose stopしてもいくつかのコンテナからエラーが出て停止できなくなってしまいました。

$ docker-compose stop
Stopping mastodon_web_1 ...
Stopping mastodon_streaming_1 ...
Stopping mastodon_sidekiq_1 ... error
Stopping mastodon_redis_1 ... error
Stopping mastodon_db_1 ... error

ERROR: for mastodon_sidekiq_1 cannot stop container: f444c(略): Cannot kill container f444c(略): process f444c(略) not found: not found

ERROR: for mastodon_streaming_1 UnixHTTPConnectionPool(host='localhost', port=None): Read timed out. (read timeout=70)

ERROR: for mastodon_web_1 UnixHTTPConnectionPool(host='localhost', port=None): Read timed out. (read timeout=70)
ERROR: An HTTP request took too long to complete. Retry with --verbose to obtain debug information.
If you encounter this issue regularly because of slow network conditions, consider setting COMPOSE_HTTP_TIMEOUT to a higher value (current value: 60).
$

そしてこの後なぜかサーバインスタンスごとクラッシュ…(ssh接続不能)

サーバインスタンスVPSコントロールパネルから再起動して、/var/log/messagesも確認。そしたら

Dec 7 06:07:01 dockerd: fatal error: concurrent map writes
Dec 7 06:07:01 systemd: docker.service: main process exited, code=exited, status=2/INVALIDARGUMENT
Dec 7 06:07:01 systemd: Unit docker.service entered failed state.
Dec 7 06:07:01 systemd: docker.service failed.
Dec 7 06:07:01 systemd: docker.service holdoff time over, scheduling restart.
Dec 7 06:07:01 systemd: Starting Docker Application Container Engine...
Dec 7 06:07:03 systemd: Started Docker Application Container Engine.

※だいぶ中間省略してます。実際は最初と最後の間にdockerdから1400行近くメッセージ出てます。

キーワードでググると下記Issueがヒット。

github.com 

ん?ひょっとしてDocker自体がクラッシュしてる?

docker-compose stop投入後OSに接続できなくなった直前、

Dec 7 10:43:39 kernel: Out of memory: Kill process 709 (dhclient) score 3 or sacrifice child
Dec 7 10:43:39 kernel: Killed process 709 (dhclient) total-vm:113372kB, anon-rss:44kB, file-rss:0kB, shmem-rss:0kB

なぜかメモリ不足?でDHCPクライアントも異常終了してしまったようです。

 サーバインスタンス再起動後、systemctl restart dockerするとMastodonコンテナが自動起動して一旦仮復旧。(まだ根本解決には至っていないけど)

 

 一応Docker環境のバージョンメモ。

# docker version
Client:
Version: 17.11.0-ce
API version: 1.34
Go version: go1.8.3
Git commit: 1caf76c
Built: Mon Nov 20 18:35:47 2017
OS/Arch: linux/amd64

Server:
Version: 17.11.0-ce
API version: 1.34 (minimum version 1.12)
Go version: go1.8.3
Git commit: 1caf76c
Built: Mon Nov 20 18:45:06 2017
OS/Arch: linux/amd64
Experimental: false

# docker-compose -v
docker-compose version 1.15.0, build e12f3b9

# docker info
Containers: 5
Running: 5
Paused: 0
Stopped: 0
Images: 53
Server Version: 17.11.0-ce
Storage Driver: overlay
Backing Filesystem: extfs
Supports d_type: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 992280e8e265f491f7a624ab82f3e238be086e49
runc version: 0351df1c5a66838d0c392b4ac4cf9450de844e2d
init version: 949e6fa
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-693.5.2.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 3
Total Memory: 1.953GiB
Name: (略)
ID: CXM4:HECZ:HVNH:(略)
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false