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 <sfrederick@vmware.com>"
3.1.x
Ivo Smid 1 year ago committed by Scott Frederick
parent 8cf686d925
commit f2a4336ea1

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

Loading…
Cancel
Save