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);