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

@@ -2,6 +2,8 @@ package io.github.hectorvent.floci.core.common.docker;
import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.command.RemoveContainerCmd;
import com.github.dockerjava.api.command.StartContainerCmd;
import com.github.dockerjava.api.exception.DockerException;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.lambda.launcher.ImageCacheService;
import org.junit.jupiter.api.BeforeEach;
@@ -14,6 +16,7 @@ import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
@@ -85,4 +88,37 @@ class ContainerLifecycleManagerStartFailureTest {
verify(dockerClient, never()).removeContainerCmd(any(String.class));
}
@Test
void startCreatedTranslatesKeyringQuotaError() {
// github.com/floci-io/floci/issues/2243: crun/runc report the kernel session-keyring
// quota (kernel.keys.maxkeys) as "Disk quota exceeded", which sends operators looking at
// disk space instead of the actual cause under high concurrent container counts.
StartContainerCmd startCmd = mock(StartContainerCmd.class);
when(dockerClient.startContainerCmd("container-id")).thenReturn(startCmd);
when(startCmd.exec()).thenThrow(new DockerException(
"crun: join keyctl '12345': Disk quota exceeded: OCI runtime error", 500));
IllegalStateException thrown = assertThrows(IllegalStateException.class,
() -> manager.startCreated("container-id", spec));
assertTrue(thrown.getMessage().contains("kernel.keys.maxkeys"),
"translated message should name the actual kernel-keyring cause: " + thrown.getMessage());
assertTrue(thrown.getMessage().contains("sysctl"),
"translated message should include the fix: " + thrown.getMessage());
}
@Test
void startCreatedPropagatesUnrelatedDockerExceptionsUnchanged() {
StartContainerCmd startCmd = mock(StartContainerCmd.class);
when(dockerClient.startContainerCmd("container-id")).thenReturn(startCmd);
DockerException portConflict = new DockerException(
"Bind for 0.0.0.0:80 failed: port is already allocated", 500);
when(startCmd.exec()).thenThrow(portConflict);
DockerException thrown = assertThrows(DockerException.class,
() -> manager.startCreated("container-id", spec));
assertSame(portConflict, thrown, "unrelated Docker errors must propagate unchanged");
}
}
@@ -388,4 +388,41 @@ class ContainerLifecycleManagerVolumeTest {
verify(dockerClient, times(2)).createContainerCmd("busybox:stable");
}
@Test
void ensureSharedVolume_startsHelperThroughTheTranslatingStartContainer() {
// github.com/floci-io/floci/issues/2243 (follow-up, PR #2797 review): the shared-volume
// init helper is a third container-start call site, distinct from createAndStart /
// startCreated and from adopt(). A failure here is caught as a plain RuntimeException by
// ensureSharedVolume's computeIfAbsent and only logged (never rethrown to the caller), so
// whether the logged message is the misleading raw "Disk quota exceeded" or the translated
// one depends entirely on whether this call site goes through startContainer(). Verifying
// startContainer("helper-id") is actually invoked (via a spy) is the only way to pin that
// routing, since the swallowed exception itself is not observable from ensureSharedVolume.
ContainerLifecycleManager spyManager = spy(manager);
doNothing().when(spyManager).startContainer("helper-id");
InspectVolumeCmd ivc = mock(InspectVolumeCmd.class);
when(dockerClient.inspectVolumeCmd("shared")).thenReturn(ivc);
when(ivc.exec()).thenReturn(mock(InspectVolumeResponse.class));
CreateContainerCmd ccc = mock(CreateContainerCmd.class, RETURNS_SELF);
when(dockerClient.createContainerCmd("busybox:stable")).thenReturn(ccc);
CreateContainerResponse resp = mock(CreateContainerResponse.class);
when(resp.getId()).thenReturn("helper-id");
when(ccc.exec()).thenReturn(resp);
WaitContainerCmd wcc = mock(WaitContainerCmd.class);
when(dockerClient.waitContainerCmd("helper-id")).thenReturn(wcc);
WaitContainerResultCallback wcb = mock(WaitContainerResultCallback.class);
when(wcc.exec(any(WaitContainerResultCallback.class))).thenReturn(wcb);
when(wcb.awaitStatusCode(anyLong(), any())).thenReturn(0);
when(dockerClient.removeContainerCmd("helper-id")).thenReturn(mock(RemoveContainerCmd.class, RETURNS_SELF));
spyManager.ensureSharedVolume("shared", OptionalInt.of(1001), OptionalInt.of(1001),
Optional.of("2775"), "busybox:stable");
verify(spyManager).startContainer("helper-id");
verify(dockerClient, never()).startContainerCmd("helper-id");
}
}