fix(docker): translate misleading disk-quota error for keyring exhaustion (#2797)

* fix(docker): translate misleading disk-quota error for keyring exhaustion

crun/runc report the kernel session-keyring quota (kernel.keys.maxkeys)
as "join keyctl ...: Disk quota exceeded", which reads as an actual
disk-space problem. Under high concurrent container counts this is
common on podman machine's default Fedora CoreOS sysctls (200 keys per
uid), and sends operators looking in the wrong place.

Both container-start call sites in ContainerLifecycleManager now go
through a shared helper that recognizes this specific OCI runtime error
and rethrows with the actual cause and the sysctl fix, leaving every
other DockerException untouched.

Fixes floci-io/floci#2243

* fix(docker): route the shared-volume init helper through the translated start path

pgermosen review on PR #2797: initSharedVolumeRoot's helper container
start bypassed the keyring-quota translation, so it still surfaced the
raw, misleading "Disk quota exceeded" message when this specific start
call hit the crun keyring error. The failure is caught as a plain
RuntimeException by ensureSharedVolume's computeIfAbsent and only
logged, never rethrown, so this exact call site's routing is what
decides which message ends up in that log line.

startContainer is now package-private so the new test can verify this
call site actually invokes it (via a spy), since the swallowed
exception itself is not observable from ensureSharedVolume's public
contract.
This commit is contained in:
Olamide Kosile authored and GitHub committed 2026-09-01 18:06:10 -04:00
1 parent bed27043ef
commit 7828ab2430
3 files changed
+108 -3

No files matched your search

@@ -32,6 +32,7 @@ import java.util.OptionalInt;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
/**
* Manages Docker container lifecycle operations including create, start, stop, and remove.
@@ -42,6 +43,13 @@ public class ContainerLifecycleManager {
private static final Logger LOG = Logger.getLogger(ContainerLifecycleManager.class);
// Matches crun/runc's "join keyctl '<id>': Disk quota exceeded" error, which the OCI runtime
// reports for the kernel session-keyring quota (kernel.keys.maxkeys), not actual disk space.
// Under high concurrent container counts (podman machine's Fedora CoreOS default is 200 keys
// per uid) this reads as a disk-space problem and sends operators looking in the wrong place.
private static final Pattern KEYRING_QUOTA_PATTERN =
Pattern.compile("join keyctl.*disk quota exceeded", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
private final DockerClient dockerClient;
private final ImageCacheService imageCacheService;
private final ContainerDetector containerDetector;
@@ -143,7 +151,7 @@ public class ContainerLifecycleManager {
* @return information about the running container including resolved endpoints
*/
public ContainerInfo startCreated(String containerId, ContainerSpec spec) {
dockerClient.startContainerCmd(containerId).exec();
startContainer(containerId);
LOG.infov("Started container {0}", containerId);
if (spec.networkMode() != null && !spec.networkMode().isBlank() && spec.hasPortBindings()) {
@@ -163,6 +171,30 @@ public class ContainerLifecycleManager {
return new ContainerInfo(containerId, endpoints);
}
/**
* Starts a container, translating crun/runc's kernel-keyring-quota error into a message that
* names the actual cause and a fix, instead of the misleading "Disk quota exceeded" the OCI
* runtime reports. Package-private so tests can verify a given call site routes through this
* translation rather than a raw {@code dockerClient.startContainerCmd(...)} call.
*/
void startContainer(String containerId) {
try {
dockerClient.startContainerCmd(containerId).exec();
} catch (DockerException e) {
String message = e.getMessage();
if (message != null && KEYRING_QUOTA_PATTERN.matcher(message).find()) {
throw new IllegalStateException(
"Container start failed: the container runtime's kernel session-keyring is "
+ "out of quota (kernel.keys.maxkeys), not disk space. This is common "
+ "under many concurrent containers on podman machine's default Fedora "
+ "CoreOS sysctls (200 keys per uid). Raise the limit in the VM, e.g.: "
+ "podman machine ssh \"sudo sysctl -w kernel.keys.maxkeys=20000 "
+ "kernel.keys.maxbytes=2000000\". Original error: " + message, e);
}
throw e;
}
}
/**
* Stops and removes a container, closing any associated log stream.
*
@@ -381,7 +413,7 @@ public class ContainerLifecycleManager {
.exec();
String helperId = created.getId();
try {
dockerClient.startContainerCmd(helperId).exec();
startContainer(helperId);
Integer status = dockerClient.waitContainerCmd(helperId)
.exec(new WaitContainerResultCallback())
.awaitStatusCode(60, TimeUnit.SECONDS);
@@ -540,7 +572,7 @@ public class ContainerLifecycleManager {
boolean running = Boolean.TRUE.equals(inspect.getState().getRunning());
if (!running) {
dockerClient.startContainerCmd(containerId).exec();
startContainer(containerId);
LOG.infov("Started adopted container {0}", containerId);
inspect = dockerClient.inspectContainerCmd(containerId).exec();
}