From 86bd883cf1d7ec19b91d0fa77582deceb0709285 Mon Sep 17 00:00:00 2001 From: jzajic Date: Tue, 27 Nov 2018 09:12:41 +0100 Subject: [PATCH] #875 - disable connection pooling for named pipe --- .../docker/client/DefaultDockerClient.java | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/spotify/docker/client/DefaultDockerClient.java b/src/main/java/com/spotify/docker/client/DefaultDockerClient.java index b2d31c208..85867c65d 100644 --- a/src/main/java/com/spotify/docker/client/DefaultDockerClient.java +++ b/src/main/java/com/spotify/docker/client/DefaultDockerClient.java @@ -181,10 +181,12 @@ import org.apache.http.config.Registry; import org.apache.http.config.RegistryBuilder; import org.apache.http.conn.ConnectTimeoutException; +import org.apache.http.conn.HttpClientConnectionManager; import org.apache.http.conn.socket.ConnectionSocketFactory; import org.apache.http.conn.socket.PlainConnectionSocketFactory; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.conn.BasicHttpClientConnectionManager; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.glassfish.hk2.api.MultiException; import org.glassfish.jersey.apache.connector.ApacheClientProperties; @@ -447,8 +449,8 @@ protected DefaultDockerClient(final Builder builder) { this.uri = originalUri; } - final PoolingHttpClientConnectionManager cm = getConnectionManager(builder); - final PoolingHttpClientConnectionManager noTimeoutCm = getConnectionManager(builder); + final HttpClientConnectionManager cm = getConnectionManager(builder); + final HttpClientConnectionManager noTimeoutCm = getConnectionManager(builder); final RequestConfig requestConfig = RequestConfig.custom() .setConnectionRequestTimeout((int) builder.connectTimeoutMillis) @@ -535,15 +537,19 @@ public String getHost() { return fromNullable(uri.getHost()).or("localhost"); } - private PoolingHttpClientConnectionManager getConnectionManager(Builder builder) { - final PoolingHttpClientConnectionManager cm = - new PoolingHttpClientConnectionManager(getSchemeRegistry(builder)); - - // Use all available connections instead of artificially limiting ourselves to 2 per server. - cm.setMaxTotal(builder.connectionPoolSize); - cm.setDefaultMaxPerRoute(cm.getMaxTotal()); - - return cm; + private HttpClientConnectionManager getConnectionManager(Builder builder) { + if (builder.uri.getScheme().equals(NPIPE_SCHEME)) { + final BasicHttpClientConnectionManager bm = + new BasicHttpClientConnectionManager(getSchemeRegistry(builder)); + return bm; + } else { + final PoolingHttpClientConnectionManager cm = + new PoolingHttpClientConnectionManager(getSchemeRegistry(builder)); + // Use all available connections instead of artificially limiting ourselves to 2 per server. + cm.setMaxTotal(builder.connectionPoolSize); + cm.setDefaultMaxPerRoute(cm.getMaxTotal()); + return cm; + } } private Registry getSchemeRegistry(final Builder builder) {