moby: docker stats hangs

Description

Docker is working for a few weeks, then it is somehow not responding anymore. Some commands work, others not. e.g. “docker stats” is hanging. “docker pa -a” works.

I searched through the various issues here that describe different hangs, but found nothing that solves my issue.

Restarting the docker daemon fixes the issue for a few days…

Steps to reproduce the issue:

  1. We just use docker and are starting / stopping containers.

Describe the results you received: Docker hangs for whatever reason.

Describe the results you expected: Docker should work as expected.

Additional information you deem important (e.g. issue happens only occasionally): In other threads there was the hint of doing a SIGUSR1-Signal to dockerd and posting the result. Also, I have done an strace on the stuck “docker stats” command. It can be found here: https://git.jar.media/snippets/8

Output of docker version:

Docker version 18.09.7, build 2d0083d

Output of docker info:

Containers: 58
 Running: 58
 Paused: 0
 Stopped: 0
Images: 776
Server Version: 18.09.7
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: 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 local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 894b81a4b802e4eb2a91d1ce216b8817763c29fb
runc version: 425e105d5a03fabd737a126ad93d62a9eeede87f
init version: fec3683
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.0-9-amd64
Operating System: Debian GNU/Linux 9 (stretch)
OSType: linux
Architecture: x86_64
CPUs: 48
Total Memory: 125.8GiB
Name: h19
ID: OJOK:YAOX:OTVB:ALUM:SZUE:ZKJD:T26K:OPEF:XP6O:33GQ:2GRT:KC36
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine

WARNING: No swap limit support

Additional environment details (AWS, VirtualBox, physical, etc.): No additional info.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 18 (9 by maintainers)

Most upvoted comments

Just a quick update.

We have fixed the logging misconfiguration issues so that all our docker containers are correctly sending logs to CloudWatch. We have then restarted the docker service on all affected instances.

There were no issues with hanging stats calls or missing metrics since.

So its quite probable that the problem with the hanging stats API was caused by the misconfigured logging and the related issue with the log driver buffers that @cpuguy83 has mentioned.

@zatlodan Thanks, I can see there are a couple of places this is getting wedged trying to close the (cloudwatch) log driver because the log buffer is full. Additionally the same thing is happening in the local log cache (used to allow docker logs to work with cloudwatch). Its trying to send the log to cloudwatch but is blocked (because of the above problem) and it is preventing the log driver from being closed.

This is causing the container state to remain locked indefinitely which is causing other issues, namely preventing an image removal from completing because some container is using the image and its trying to take the container lock to see if the container is running… I think this is also another bug, we shouldn’t care if the container is running or not here… but there are likely historical reasons for why this is the way it is. I’ll try and take a look at this as well.

On the stuck instances, please grab a goroutine stack dump.

You can get this from the endpoint t “/debug/pprof/goroutine?debug=2”

Also please provide the output of “docker info” and “docker version”, assuming those work (they shouldn’t generally get wedged).

Starting and stopping a few tens (~30) containers simultaneously and continuously with periodic docker stats API invocation, the stats API gets hang at a random time and often makes deadlocks for my container termination routines which calls the stats API to sync the final stats to an internal database. For testing, each container run just a simple “sleep” command for a few seconds, so there is no computational overheads of containers, though we are controlling the containers via our own “job scheduler” implementation. Maybe there is a race condition issue inside the stats API implementation when the container terminates.

FYI: I have an alternative stats implementation which reads and parses the sysfs directly, and using it instead of the docker stats API resolves the deadlock issue completely, under heavy-load tests. So I’m pretty sure that the problem resides inside the docker daemon somewhere…