feat(core): make the Docker call timeout configurable (#5431)

* feat(core): make the Docker call timeout configurable

Ordinary Docker calls failed after a hard-coded five minutes without a
response. floci.docker.api-timeout-seconds (FLOCI_DOCKER_API_TIMEOUT_SECONDS)
now sets it for both pools, defaulting to 300 so nothing changes by
default; a shorter value bounds how long a hung daemon can hold a request.
Like the connection request timeout, it must be at least 1, because
httpclient5 reads 0 as no limit. Long-lived streams (container waits, exec
and attach output, followed logs, streamed stats, events, image pulls and
builds) stay exempt.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>

* docs(core): say the Docker call timeout applies to each attempt

The control-plane pool retries a request that is safe to repeat up to six
times, and a response timeout is one of the failures it retries. The docs,
the config Javadoc and the application.yml comment said the setting bounds
a request; it bounds each attempt, so a silent daemon can hold a replayable
request for about six times the limit, plus backoff.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>

---------

Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-10-11 00:17:11 -04:00
1 parent 61fe304619
commit 98100054a8
6 files changed
+71 -5

No files matched your search

+9 -1
View File
@@ -82,7 +82,15 @@ floci:
Environment variable: `FLOCI_DOCKER_CONNECTION_REQUEST_TIMEOUT_SECONDS`
A Docker call that gets no response within 5 minutes fails, on Unix-socket and TCP hosts alike. Requests that follow a container for as long as it runs (container waits, exec and attach output, followed logs, streamed stats, daemon events, image pulls and builds) have no such limit, since they can stay silent while healthy.
A Docker call that gets no response within `api-timeout-seconds` fails, on Unix-socket and TCP hosts alike, so a hung daemon cannot block a request indefinitely. The limit applies to each attempt: a control-plane request that is safe to repeat is tried up to six times, so against a silent daemon it can take about six times the limit, plus backoff, to fail. It defaults to 300 seconds (5 minutes) for both pools and must be at least 1, since httpclient5 reads 0 as no limit. Requests that follow a container for as long as it runs (container waits, exec and attach output, followed logs, streamed stats, daemon events, image pulls and builds) have no such limit, since they can stay silent while healthy:
```yaml
floci:
docker:
api-timeout-seconds: 300
```
Environment variable: `FLOCI_DOCKER_API_TIMEOUT_SECONDS`
## Private Registry Authentication
@@ -3540,6 +3540,16 @@ public interface EmulatorConfig {
@WithDefault("30")
int connectionRequestTimeoutSeconds();
/**
* How long a Docker call waits for the daemon's response before it fails, in seconds, for
* both pools. The limit is per attempt: a control-plane request that is safe to repeat is
* tried up to six times. Requests that hold a stream open for as long as a container runs (container
* waits, exec and attach output, followed logs, streamed stats, events, image pulls and
* builds) are exempt, since they can stay silent while healthy.
*/
@WithDefault("300")
int apiTimeoutSeconds();
/**
* Optional namespace inserted into Floci-managed child container and volume names.
* Useful when multiple Floci processes share one Docker daemon.
@@ -419,6 +419,10 @@ public class DockerClientProducer {
"FLOCI_DOCKER_CONNECTION_REQUEST_TIMEOUT_SECONDS");
}
static int validateApiTimeoutSeconds(int seconds) {
return requireAtLeastOne(seconds, "floci.docker.api-timeout-seconds", "FLOCI_DOCKER_API_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);
@@ -497,18 +501,19 @@ public class DockerClientProducer {
role, maxConnections, clientConfig.getDockerHost());
return DockerClientImpl.getInstance(clientConfig, wrapForRole(newHttpClient(clientConfig, maxConnections,
Duration.ofSeconds(validateApiTimeoutSeconds(config.docker().apiTimeoutSeconds())),
Duration.ofSeconds(validateConnectionRequestTimeoutSeconds(
config.docker().connectionRequestTimeoutSeconds()))), role));
}
static FlociDockerHttpClient newHttpClient(DefaultDockerClientConfig clientConfig, int maxConnections,
Duration connectionRequestTimeout) {
Duration apiTimeout, Duration connectionRequestTimeout) {
return new FlociDockerHttpClient.Builder()
.dockerHost(clientConfig.getDockerHost())
.sslConfig(clientConfig.getSSLConfig())
.maxConnections(maxConnections)
.connectionTimeout(Duration.ofSeconds(30))
.responseTimeout(Duration.ofMinutes(5))
.responseTimeout(apiTimeout)
.connectionRequestTimeout(connectionRequestTimeout)
.build();
}
+5
View File
@@ -326,6 +326,11 @@ floci:
# connection before failing, for both pools. Keep in step with the @WithDefault on
# EmulatorConfig.DockerConfig.connectionRequestTimeoutSeconds: a value set here WINS over the annotation.
connection-request-timeout-seconds: 30
# FLOCI_DOCKER_API_TIMEOUT_SECONDS: how long a Docker call waits for the daemon's response before
# failing; long-lived streams (waits, followed logs, exec output, pulls) are exempt. It applies per
# attempt: a control-plane request that is safe to repeat is tried up to six times. Keep in step with
# the @WithDefault on EmulatorConfig.DockerConfig.apiTimeoutSeconds: a value set here WINS over the annotation.
api-timeout-seconds: 300
resource-namespace: "" # FLOCI_DOCKER_RESOURCE_NAMESPACE; scopes child container/volume names
docker-config-path: ""
# extra-labels: # Extra Docker labels applied to every Floci-created container and volume
@@ -172,4 +172,23 @@ class ApplicationDefaultsTest {
assertEquals("30", fallback.value(),
"the @WithDefault must match application.yml, which wins over it");
}
// Catches: api-timeout-seconds missing from the shipped application.yml, or a yml value that
// silently disagrees with the @WithDefault fallback.
@Test
void productionConfigDeclaresTheDockerApiTimeoutAtItsDefault() throws IOException, NoSuchMethodException {
JsonNode apiTimeout = new YAMLMapper()
.readTree(Path.of("src/main/resources/application.yml").toFile())
.path("floci").path("docker").path("api-timeout-seconds");
assertFalse(apiTimeout.isMissingNode(), "api-timeout-seconds should be declared in application.yml");
assertEquals(300, apiTimeout.asInt());
WithDefault fallback = EmulatorConfig.DockerConfig.class
.getMethod("apiTimeoutSeconds")
.getAnnotation(WithDefault.class);
assertNotNull(fallback, "apiTimeoutSeconds should declare a fallback default");
assertEquals("300", fallback.value(),
"the @WithDefault must match application.yml, which wins over it");
}
}
@@ -274,6 +274,7 @@ class DockerClientProducerTest {
when(docker.maxConnections()).thenReturn(100);
when(docker.streamingMaxConnections()).thenReturn(512);
when(docker.connectionRequestTimeoutSeconds()).thenReturn(30);
when(docker.apiTimeoutSeconds()).thenReturn(300);
DockerClientProducer producer = new DockerClientProducer(config);
@@ -689,6 +690,23 @@ class DockerClientProducerTest {
assertEquals(30, DockerClientProducer.validateConnectionRequestTimeoutSeconds(30));
}
// Catches: a zero response timeout reaching httpclient5, which reads it as no timeout, so a
// hung daemon would hold a call forever.
@ParameterizedTest
@ValueSource(ints = {0, -1})
void validateApiTimeoutSeconds_belowOne_throwsNamingTheSetting(int seconds) {
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
() -> DockerClientProducer.validateApiTimeoutSeconds(seconds));
assertThat(e.getMessage(), containsString("floci.docker.api-timeout-seconds"));
}
@Test
void validateApiTimeoutSeconds_positive_returnsItUnchanged() {
assertEquals(1, DockerClientProducer.validateApiTimeoutSeconds(1));
assertEquals(300, DockerClientProducer.validateApiTimeoutSeconds(300));
}
/**
* 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
@@ -717,6 +735,7 @@ class DockerClientProducerTest {
when(docker.dockerConfigPath()).thenReturn(Optional.empty());
when(docker.maxConnections()).thenReturn(2);
when(docker.connectionRequestTimeoutSeconds()).thenReturn(30);
when(docker.apiTimeoutSeconds()).thenReturn(300);
DockerClient client = new DockerClientProducer(config).dockerClient();
try {
@@ -761,7 +780,7 @@ class DockerClientProducerTest {
// An HTTP client that actually uses the SSL config must read the certificates, so
// unreadable ones fail the build; one that ignores the config builds silently.
assertThrows(RuntimeException.class,
() -> DockerClientProducer.newHttpClient(tlsConfig, 10, Duration.ofSeconds(30)));
() -> DockerClientProducer.newHttpClient(tlsConfig, 10, Duration.ofMinutes(5), Duration.ofSeconds(30)));
}
@Test
@@ -774,7 +793,7 @@ class DockerClientProducerTest {
.build();
try (FlociDockerHttpClient client =
DockerClientProducer.newHttpClient(plainConfig, 10, Duration.ofSeconds(30))) {
DockerClientProducer.newHttpClient(plainConfig, 10, Duration.ofMinutes(5), Duration.ofSeconds(30))) {
assertNull(plainConfig.getSSLConfig(), "a config without TLS verify carries no SSL config");
assertEquals("tcp://127.0.0.1:2375", plainConfig.getDockerHost().toString());
}