diff --git a/README.md b/README.md index bfc3d73..d761079 100644 --- a/README.md +++ b/README.md @@ -251,6 +251,43 @@ Storage Driver: overlayfs Cached images and builds in the old dind store are discarded by this reset. +## gVisor session keyring exhaustion + +A long-running dind sandbox can eventually fail to start any new container: + +```text +failed to create task for container: failed to create shim task: +OCI runtime create failed: runc create failed: unable to start container +process: error during container init: unable to join session keyring: +unable to create session key: disk quota exceeded +``` + +This is a gVisor keyring leak, not a disk-space problem. runc creates a new +session keyring (`_ses.`) for every container, and affected +gVisor releases keep those keyrings forever. gVisor limits a user namespace to +200 keys, so after roughly 200 container creations every further +`KEYCTL_JOIN_SESSION_KEYRING` fails with `EDQUOT`. Restarting dind clears the +sandbox's key set temporarily. + +The dind startup script raises gVisor's `/proc/sys/kernel/keys/maxkeys` to +`50000` before starting dockerd. This only delays exhaustion; it does not fix +the leak. Override the limit with `GVISOR_KEY_MAXKEYS`, for example: + +```yaml +services: + dind: + environment: + GVISOR_KEY_MAXKEYS: "100000" +``` + +The script only changes the sysctl when `/proc/version` identifies gVisor, so +running the same image under a runc dind does not modify the host-wide limit. +Remove this workaround once the dind host uses a gVisor release that releases +session keyrings when their last holder exits. Upstream discussion: + +- https://github.com/google/gvisor/pull/16231 +- https://github.com/google/gvisor/pull/16232 + ## Workspace bind mounts inside jobs A workflow step such as: diff --git a/gvisor/images/basic/docker/start-dockerd.sh b/gvisor/images/basic/docker/start-dockerd.sh index 041960e..4f30c97 100755 --- a/gvisor/images/basic/docker/start-dockerd.sh +++ b/gvisor/images/basic/docker/start-dockerd.sh @@ -40,6 +40,31 @@ while [[ $# -gt 0 ]]; do esac done +# Temporary workaround for gVisor's session keyring leak. +# +# runc creates a new session keyring for every container it starts. gVisor +# (through at least release-20261102.0) never releases those keyrings and caps +# each user namespace's key set at 200. Once the cap is reached, creating any +# new container fails with: +# +# unable to join session keyring: unable to create session key: disk quota exceeded +# +# Raise the cap far enough that a long-running CI dind lasts longer. This does +# not stop the leak; remove it once gVisor releases session keyrings upstream. +# Only write the sysctl inside gVisor: on a runc DinD this is the host-wide key +# limit and changing it would affect the host. +if grep -qi gvisor /proc/version; then + key_maxkeys="${GVISOR_KEY_MAXKEYS:-50000}" + current_key_maxkeys=$(cat /proc/sys/kernel/keys/maxkeys 2>/dev/null || true) + if [[ "${key_maxkeys}" =~ ^[0-9]+$ ]] && (( key_maxkeys > 0 )) && \ + [[ "${current_key_maxkeys}" =~ ^[0-9]+$ ]] && \ + (( current_key_maxkeys < key_maxkeys )); then + echo "Raising gVisor session keyring limit from ${current_key_maxkeys} to ${key_maxkeys}" + echo "${key_maxkeys}" > /proc/sys/kernel/keys/maxkeys || \ + echo "warning: failed to raise gVisor session keyring limit" >&2 + fi +fi + # When dockerd uses the overlay storage driver, it will try to mount an overlay # filesystem under /var/lib/docker. gVisor only supports tmpfs as an upper # layer, so we mount a tmpfs if it isn't already present.