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

@@ -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());
}