mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
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:
1 parent
f8f47914a0
commit
66756f7b9c
2 files changed
+27
-7
No files matched your search
+16
-7
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user