feat(core): make the image pull timeout configurable (#6521)

ImageCacheService gave each attempt at pulling an image a hard-coded
five minutes, and a pull three attempts. An EMR Serverless runtime is
3.5 to 4.3 GB, so on an ordinary connection the first run of a release
Docker did not have yet failed with "Could not pull image" before the
pull could finish.

floci.docker.image-pull-timeout-seconds, or
FLOCI_DOCKER_IMAGE_PULL_TIMEOUT_SECONDS, now sets the limit for each
attempt. Its default, 300, keeps today's five minutes, and it must be
at least 1, checked with the other Docker timeouts in
DockerClientProducer.

Follow-up to #6469.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-10-25 14:08:34 -05:00
1 parent 1ea49d9432
commit b66ee9ecf0
8 files changed
+89 -8

No files matched your search

@@ -692,6 +692,22 @@ class DockerClientProducerTest {
assertEquals(300, DockerClientProducer.validateApiTimeoutSeconds(300));
}
// Catches: a zero pull timeout, which would give up on every pull at once.
@ParameterizedTest
@ValueSource(ints = {0, -1})
void validateImagePullTimeoutSeconds_belowOne_throwsNamingTheSetting(int seconds) {
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
() -> DockerClientProducer.validateImagePullTimeoutSeconds(seconds));
assertThat(e.getMessage(), containsString("floci.docker.image-pull-timeout-seconds"));
}
@Test
void validateImagePullTimeoutSeconds_positive_returnsItUnchanged() {
assertEquals(1, DockerClientProducer.validateImagePullTimeoutSeconds(1));
assertEquals(1800, DockerClientProducer.validateImagePullTimeoutSeconds(1800));
}
/**
* The pool size comes from {@code floci.docker.max-connections}. A followed log stream holds
* its connection until the container exits, and this fake daemon never answers, so with a
@@ -32,6 +32,7 @@ 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.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.mock;
@@ -67,7 +68,28 @@ class ImageCacheServiceTest {
verify(pullImage).exec(any(PullImageResultCallback.class));
verify(pullImage, never()).withPlatform(nullable(String.class));
verify(callback).awaitCompletion(5, TimeUnit.MINUTES);
verify(callback).awaitCompletion(300, TimeUnit.SECONDS);
}
@Test
void eachPullAttemptWaitsAsLongAsTheConfiguredImagePullTimeout() throws Exception {
DockerClient dockerClient = mock(DockerClient.class);
InspectImageCmd inspectImage = mock(InspectImageCmd.class);
PullImageCmd pullImage = mock(PullImageCmd.class);
PullImageResultCallback callback = completedPull();
when(dockerClient.inspectImageCmd(IMAGE)).thenReturn(inspectImage);
when(inspectImage.exec()).thenThrow(new NotFoundException("image not found"))
.thenReturn(new InspectImageResponse()
.withId("sha256:native")
.withOs("linux")
.withArch("amd64"));
when(dockerClient.pullImageCmd(IMAGE)).thenReturn(pullImage);
when(pullImage.withAuthConfig(any())).thenReturn(pullImage);
when(pullImage.exec(any(PullImageResultCallback.class))).thenReturn(callback);
newService(dockerClient, 1800).ensureImageExists(IMAGE);
verify(callback).awaitCompletion(1800, TimeUnit.SECONDS);
}
@Test
@@ -105,7 +127,7 @@ class ImageCacheServiceTest {
assertEquals("sha256:arm64", resolvedImage);
verify(pullImage).withPlatform("linux/arm64");
verify(callback).awaitCompletion(5, TimeUnit.MINUTES);
verify(callback).awaitCompletion(300, TimeUnit.SECONDS);
}
@Test
@@ -697,11 +719,15 @@ class ImageCacheServiceTest {
private static PullImageResultCallback completedPull() throws InterruptedException {
PullImageResultCallback callback = mock(PullImageResultCallback.class);
when(callback.awaitCompletion(5, TimeUnit.MINUTES)).thenReturn(true);
when(callback.awaitCompletion(anyLong(), any(TimeUnit.class))).thenReturn(true);
return callback;
}
private static ImageCacheService newService(DockerClient dockerClient) {
return newService(dockerClient, 300);
}
private static ImageCacheService newService(DockerClient dockerClient, int imagePullTimeoutSeconds) {
InfoCmd infoCmd = mock(InfoCmd.class);
when(dockerClient.infoCmd()).thenReturn(infoCmd);
when(infoCmd.exec()).thenReturn(new Info().withOsType("linux").withArchitecture("amd64"));
@@ -709,6 +735,7 @@ class ImageCacheServiceTest {
EmulatorConfig.DockerConfig dockerConfig = mock(EmulatorConfig.DockerConfig.class);
when(config.docker()).thenReturn(dockerConfig);
when(dockerConfig.registryCredentials()).thenReturn(List.of());
when(dockerConfig.imagePullTimeoutSeconds()).thenReturn(imagePullTimeoutSeconds);
return new ImageCacheService(dockerClient, config);
}
}