From f2a4336ea10884a486746950ff7935f300d66730 Mon Sep 17 00:00:00 2001 From: Ivo Smid Date: Wed, 30 Aug 2023 21:32:34 +0200 Subject: [PATCH] Increase the socket timeout for remote connections to Docker daemon The default socket timeout with HttpClient 5 is not long enough in some cases where Docker images are built that require the GraalVM native image compiler to run in a buildpack. This commit increases the timeout to 30 minutes. Fixes gh-37665 Co-authored-by: Scott Frederick " --- .../transport/RemoteHttpClientTransport.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/RemoteHttpClientTransport.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/RemoteHttpClientTransport.java index 67dade3b65..0ab8d1ef6e 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/RemoteHttpClientTransport.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/RemoteHttpClientTransport.java @@ -17,17 +17,19 @@ package org.springframework.boot.buildpack.platform.docker.transport; import java.net.URISyntaxException; +import java.util.concurrent.TimeUnit; import javax.net.ssl.SSLContext; import org.apache.hc.client5.http.classic.HttpClient; import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; import org.apache.hc.client5.http.impl.classic.HttpClients; -import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager; import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder; import org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory; import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory; import org.apache.hc.core5.http.HttpHost; +import org.apache.hc.core5.http.io.SocketConfig; +import org.apache.hc.core5.util.Timeout; import org.springframework.boot.buildpack.platform.docker.configuration.DockerHost; import org.springframework.boot.buildpack.platform.docker.configuration.ResolvedDockerHost; @@ -42,6 +44,8 @@ import org.springframework.util.Assert; */ final class RemoteHttpClientTransport extends HttpClientTransport { + private static final Timeout SOCKET_TIMEOUT = Timeout.of(30, TimeUnit.MINUTES); + private RemoteHttpClientTransport(HttpClient client, HttpHost host) { super(client, host); } @@ -65,13 +69,15 @@ final class RemoteHttpClientTransport extends HttpClientTransport { private static RemoteHttpClientTransport create(DockerHost host, SslContextFactory sslContextFactory, HttpHost tcpHost) { - HttpClientBuilder builder = HttpClients.custom(); + SocketConfig socketConfig = SocketConfig.copy(SocketConfig.DEFAULT).setSoTimeout(SOCKET_TIMEOUT).build(); + PoolingHttpClientConnectionManagerBuilder connectionManagerBuilder = PoolingHttpClientConnectionManagerBuilder + .create() + .setDefaultSocketConfig(socketConfig); if (host.isSecure()) { - PoolingHttpClientConnectionManager connectionManager = PoolingHttpClientConnectionManagerBuilder.create() - .setSSLSocketFactory(getSecureConnectionSocketFactory(host, sslContextFactory)) - .build(); - builder.setConnectionManager(connectionManager); + connectionManagerBuilder.setSSLSocketFactory(getSecureConnectionSocketFactory(host, sslContextFactory)); } + HttpClientBuilder builder = HttpClients.custom(); + builder.setConnectionManager(connectionManagerBuilder.build()); String scheme = host.isSecure() ? "https" : "http"; HttpHost httpHost = new HttpHost(scheme, tcpHost.getHostName(), tcpHost.getPort()); return new RemoteHttpClientTransport(builder.build(), httpHost);