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

@@ -3880,6 +3880,15 @@ public interface EmulatorConfig {
@WithDefault("300")
int apiTimeoutSeconds();
/**
* How long each attempt at pulling an image may take before it is given up, in seconds. A pull
* still downloading when the limit passes is tried again, three attempts in all, so a launch that
* needs an image can wait up to about three times this before it fails. A large image, such as an EMR Serverless runtime of 3.5 to 4.3 GB, can need longer
* on a slow connection.
*/
@WithDefault("300")
int imagePullTimeoutSeconds();
/**
* Optional namespace inserted into Floci-managed child container and volume names.
* Useful when multiple Floci processes share one Docker daemon.
@@ -407,6 +407,12 @@ public class DockerClientProducer {
return requireAtLeastOne(seconds, "floci.docker.api-timeout-seconds", "FLOCI_DOCKER_API_TIMEOUT_SECONDS");
}
/** At 0 every pull would be given up at once, so a launch that needs an image could never start. */
public static int validateImagePullTimeoutSeconds(int seconds) {
return requireAtLeastOne(seconds, "floci.docker.image-pull-timeout-seconds",
"FLOCI_DOCKER_IMAGE_PULL_TIMEOUT_SECONDS");
}
private static int requireAtLeastOne(int value, String setting, String envVar) {
if (value < 1) {
throw new IllegalArgumentException(setting + " (" + envVar + ") must be at least 1, got: " + value);
@@ -11,6 +11,7 @@ import com.github.dockerjava.api.model.Info;
import com.github.dockerjava.api.model.PullResponseItem;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.config.EmulatorConfig.EcsServiceConfig.ImagePullBehavior;
import io.github.hectorvent.floci.core.common.docker.DockerClientProducer;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.jboss.logging.Logger;
@@ -44,6 +45,8 @@ public class ImageCacheService {
private final DockerClient dockerClient;
private final List<EmulatorConfig.DockerConfig.RegistryCredential> registryCredentials;
// floci.docker.image-pull-timeout-seconds: how long each pull attempt may take.
private final int pullTimeoutSeconds;
private final Map<ImageKey, String> resolvedImages = new ConcurrentHashMap<>();
private final Set<ImageKey> pulledImages = ConcurrentHashMap.newKeySet();
private final ConcurrentHashMap<String, Object> locks = new ConcurrentHashMap<>();
@@ -53,6 +56,8 @@ public class ImageCacheService {
public ImageCacheService(DockerClient dockerClient, EmulatorConfig config) {
this.dockerClient = dockerClient;
this.registryCredentials = config.docker().registryCredentials();
this.pullTimeoutSeconds = DockerClientProducer.validateImagePullTimeoutSeconds(
config.docker().imagePullTimeoutSeconds());
}
public String ensureImageExists(String imageUri) {
@@ -186,8 +191,10 @@ public class ImageCacheService {
}
ManifestDigestCallback callback = new ManifestDigestCallback();
lastAttempt.set(callback);
if (!pullImage.<PullImageResultCallback>exec(callback).awaitCompletion(5, TimeUnit.MINUTES)) {
throw new DockerClientException("Timed out pulling image " + imageUri + " after 5 minutes");
if (!pullImage.<PullImageResultCallback>exec(callback)
.awaitCompletion(pullTimeoutSeconds, TimeUnit.SECONDS)) {
throw new DockerClientException("Timed out pulling image " + imageUri + " after "
+ pullTimeoutSeconds + " seconds");
}
});
} catch (InterruptedException e) {