Skip to content

Commit

Permalink
Increase the socket timeout for remote connections to Docker daemon
Browse files Browse the repository at this point in the history
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>"
  • Loading branch information
bedla authored and scottfrederick committed Oct 3, 2023
1 parent 8cf686d commit f2a4336
Showing 1 changed file with 12 additions and 6 deletions.
Expand Up @@ -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;
Expand All @@ -42,6 +44,8 @@
*/
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);
}
Expand All @@ -65,13 +69,15 @@ static RemoteHttpClientTransport createIfPossible(ResolvedDockerHost dockerHost,

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

0 comments on commit f2a4336

Please sign in to comment.