fix(docker): skip stale connection checks for named pipes (#5400)

Disable stale connection validation for named-pipe endpoints because Docker may block while the HTTP client checks pooled connections. Keep the existing validation for TCP and Unix sockets.

Fix #5394
This commit is contained in:
Victor Marques authored and GitHub committed 2026-10-14 19:39:38 -04:00
1 parent f8f47914a0
commit 66756f7b9c
2 files changed
+27 -7

No files matched your search

@@ -66,10 +66,12 @@ import java.util.stream.Stream;
* docker-java's settings (npipe and tcp hosts, TLS from the SSL config, a pool of
* {@code maxConnections} for one route, no socket read timeout on the pool, hijacked exec/attach
* upgrades through {@link HijackingHttpRequestExecutor}), validates a pooled connection idle over a
* second before reusing it and evicts idle ones, where docker-java disabled both, and differs in two
* more ways: a {@code unix://} host connects through {@link UnixDomainSocket}, which honours read
* timeouts where docker-java's socket ignored them, and requests that hold a stream open get no
* response timeout ({@link #isLongLivedStream}), while every other call keeps it.
* second before reuse on transports that honour socket read timeouts, and evicts idle ones, where
* docker-java disabled both. A {@code unix://} host connects through {@link UnixDomainSocket},
* which honours read timeouts where docker-java's socket ignored them. Named pipes skip stale
* validation because docker-java's {@link NamedPipeSocket} read can block despite the 1 ms timeout
* used by httpclient5's validation check. Requests that hold a stream open get no response timeout
* ({@link #isLongLivedStream}), while every other call keeps it.
*/
public final class FlociDockerHttpClient implements DockerHttpClient {
@@ -121,11 +123,12 @@ public final class FlociDockerHttpClient implements DockerHttpClient {
.build());
connectionManager.setMaxTotal(maxConnections);
connectionManager.setDefaultMaxPerRoute(maxConnections);
connectionManager.setDefaultConnectionConfig(ConnectionConfig.custom()
.setValidateAfterInactivity(VALIDATE_AFTER_INACTIVITY)
ConnectionConfig connectionConfig = ConnectionConfig.custom()
.setValidateAfterInactivity(staleConnectionValidationFor(dockerHost))
.setConnectTimeout(connectionTimeout != null
? Timeout.of(connectionTimeout.toNanos(), TimeUnit.NANOSECONDS) : null)
.build());
.build();
connectionManager.setDefaultConnectionConfig(connectionConfig);
RequestConfig requestConfig = RequestConfig.custom()
.setResponseTimeout(responseTimeout != null
@@ -172,6 +175,12 @@ public final class FlociDockerHttpClient implements DockerHttpClient {
name -> "https".equalsIgnoreCase(name) ? tlsSocketStrategy : null);
}
/** Selects stale validation only when the socket honours its short read timeout. */
static TimeValue staleConnectionValidationFor(URI dockerHost) {
return "npipe".equalsIgnoreCase(dockerHost.getScheme())
? TimeValue.NEG_ONE_MILLISECOND : VALIDATE_AFTER_INACTIVITY;
}
@Override
public Response execute(Request request) {
HttpContext context = new HttpCoreContext();
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.core.common.docker;
import com.github.dockerjava.transport.DockerHttpClient;
import org.apache.hc.core5.http.ConnectionRequestTimeoutException;
import org.apache.hc.core5.util.TimeValue;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.io.TempDir;
@@ -34,6 +35,16 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
class FlociDockerHttpClientTest {
@Test
void staleConnectionValidationOnlyUsesSocketsThatHonorReadTimeouts() {
assertEquals(TimeValue.ofSeconds(1), FlociDockerHttpClient.staleConnectionValidationFor(
URI.create("unix:///var/run/docker.sock")));
assertEquals(TimeValue.ofSeconds(1), FlociDockerHttpClient.staleConnectionValidationFor(
URI.create("tcp://127.0.0.1:2375")));
assertEquals(TimeValue.NEG_ONE_MILLISECOND, FlociDockerHttpClient.staleConnectionValidationFor(
URI.create("npipe:////./pipe/docker_engine")));
}
// Catches: a full pool making a call wait out httpclient5's three-minute default instead of
// failing after the configured lease timeout.
@Test