mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(core): fail a Docker call after 30 seconds when its connection pool is full (#5285)
* fix(core): fail a Docker call after 30 seconds when its connection pool is full With no connection-request timeout set, a call that could not lease a pooled connection waited httpclient5's default three minutes before failing. A full pool means the emulator is saturated, so the wait is now configurable through floci.docker.connection-request-timeout-seconds (default 30), applied to both pools. The transport retry already treats a lease timeout as pool exhaustion and never replays it, so the call fails once, after the timeout. * fix(core): reject a Docker lease timeout below one second httpclient5 reads a zero connection-request timeout as no timeout, so floci.docker.connection-request-timeout-seconds=0 let a call on a full pool wait forever, and a negative value reached the client unchecked. It now has to be at least 1, checked the way the two pool sizes are, through one helper that names the setting and its environment variable. The two producer tests that build the beans from a mocked config now stub the timeout; they ran with zero before. The lease test's socket list is shared with the acceptor thread, so it is a concurrent list.
This commit is contained in:
1 parent
2c2ac5dbfa
commit
985921c3db
8 files changed
+183
-17
No files matched your search
@@ -3516,6 +3516,15 @@ public interface EmulatorConfig {
|
||||
@WithDefault("512")
|
||||
int streamingMaxConnections();
|
||||
|
||||
/**
|
||||
* How long a Docker call waits for a free pooled connection before it fails with
|
||||
* {@code ConnectionRequestTimeoutException}, in seconds, for both pools. A full pool means
|
||||
* the emulator is saturated, so failing sooner beats httpclient5's default three-minute wait;
|
||||
* the transport retry never replays a lease timeout.
|
||||
*/
|
||||
@WithDefault("30")
|
||||
int connectionRequestTimeoutSeconds();
|
||||
|
||||
/**
|
||||
* Optional namespace inserted into Floci-managed child container and volume names.
|
||||
* Useful when multiple Floci processes share one Docker daemon.
|
||||
|
||||
+24
-13
@@ -401,21 +401,29 @@ public class DockerClientProducer {
|
||||
* connection pool to reject it with a generic error.
|
||||
*/
|
||||
static int validateMaxConnections(int maxConnections) {
|
||||
if (maxConnections < 1) {
|
||||
throw new IllegalArgumentException("floci.docker.max-connections (FLOCI_DOCKER_MAX_CONNECTIONS) "
|
||||
+ "must be at least 1, got: " + maxConnections);
|
||||
}
|
||||
return maxConnections;
|
||||
return requireAtLeastOne(maxConnections, "floci.docker.max-connections", "FLOCI_DOCKER_MAX_CONNECTIONS");
|
||||
}
|
||||
|
||||
/** Same check as {@link #validateMaxConnections(int)}, for the streaming pool's setting. */
|
||||
static int validateStreamingMaxConnections(int streamingMaxConnections) {
|
||||
if (streamingMaxConnections < 1) {
|
||||
throw new IllegalArgumentException("floci.docker.streaming-max-connections "
|
||||
+ "(FLOCI_DOCKER_STREAMING_MAX_CONNECTIONS) must be at least 1, got: "
|
||||
+ streamingMaxConnections);
|
||||
return requireAtLeastOne(streamingMaxConnections, "floci.docker.streaming-max-connections",
|
||||
"FLOCI_DOCKER_STREAMING_MAX_CONNECTIONS");
|
||||
}
|
||||
|
||||
/**
|
||||
* Rejects a lease timeout below 1 second: httpclient5 reads zero as no timeout at all, so a
|
||||
* call would wait forever on a full pool, and a negative value fails deep inside the client.
|
||||
*/
|
||||
static int validateConnectionRequestTimeoutSeconds(int seconds) {
|
||||
return requireAtLeastOne(seconds, "floci.docker.connection-request-timeout-seconds",
|
||||
"FLOCI_DOCKER_CONNECTION_REQUEST_TIMEOUT_SECONDS");
|
||||
}
|
||||
|
||||
private static int requireAtLeastOne(int value, String setting, String envVar) {
|
||||
if (value < 1) {
|
||||
throw new IllegalArgumentException(setting + " (" + envVar + ") must be at least 1, got: " + value);
|
||||
}
|
||||
return streamingMaxConnections;
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -488,17 +496,20 @@ public class DockerClientProducer {
|
||||
LOG.infov("Creating {0} DockerClient pool (maxConnections={1}) for host: {2}",
|
||||
role, maxConnections, clientConfig.getDockerHost());
|
||||
|
||||
return DockerClientImpl.getInstance(clientConfig,
|
||||
wrapForRole(newHttpClient(clientConfig, maxConnections), role));
|
||||
return DockerClientImpl.getInstance(clientConfig, wrapForRole(newHttpClient(clientConfig, maxConnections,
|
||||
Duration.ofSeconds(validateConnectionRequestTimeoutSeconds(
|
||||
config.docker().connectionRequestTimeoutSeconds()))), role));
|
||||
}
|
||||
|
||||
static FlociDockerHttpClient newHttpClient(DefaultDockerClientConfig clientConfig, int maxConnections) {
|
||||
static FlociDockerHttpClient newHttpClient(DefaultDockerClientConfig clientConfig, int maxConnections,
|
||||
Duration connectionRequestTimeout) {
|
||||
return new FlociDockerHttpClient.Builder()
|
||||
.dockerHost(clientConfig.getDockerHost())
|
||||
.sslConfig(clientConfig.getSSLConfig())
|
||||
.maxConnections(maxConnections)
|
||||
.connectionTimeout(Duration.ofSeconds(30))
|
||||
.responseTimeout(Duration.ofMinutes(5))
|
||||
.connectionRequestTimeout(connectionRequestTimeout)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
+16
-2
@@ -74,7 +74,8 @@ public final class FlociDockerHttpClient implements DockerHttpClient {
|
||||
private final String pathPrefix;
|
||||
|
||||
private FlociDockerHttpClient(URI dockerHost, SSLConfig sslConfig, int maxConnections,
|
||||
Duration connectionTimeout, Duration responseTimeout) {
|
||||
Duration connectionTimeout, Duration responseTimeout,
|
||||
Duration connectionRequestTimeout) {
|
||||
SSLContext sslContext;
|
||||
try {
|
||||
sslContext = sslConfig != null ? sslConfig.getSSLContext() : null;
|
||||
@@ -115,6 +116,8 @@ public final class FlociDockerHttpClient implements DockerHttpClient {
|
||||
.setDefaultRequestConfig(RequestConfig.custom()
|
||||
.setResponseTimeout(responseTimeout != null
|
||||
? Timeout.of(responseTimeout.toNanos(), TimeUnit.NANOSECONDS) : null)
|
||||
.setConnectionRequestTimeout(connectionRequestTimeout != null
|
||||
? Timeout.of(connectionRequestTimeout.toNanos(), TimeUnit.NANOSECONDS) : null)
|
||||
.build())
|
||||
.disableConnectionState()
|
||||
.build();
|
||||
@@ -193,6 +196,7 @@ public final class FlociDockerHttpClient implements DockerHttpClient {
|
||||
private int maxConnections = Integer.MAX_VALUE;
|
||||
private Duration connectionTimeout;
|
||||
private Duration responseTimeout;
|
||||
private Duration connectionRequestTimeout;
|
||||
|
||||
public Builder dockerHost(URI value) {
|
||||
this.dockerHost = Objects.requireNonNull(value, "dockerHost");
|
||||
@@ -219,9 +223,19 @@ public final class FlociDockerHttpClient implements DockerHttpClient {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* How long a call waits to lease a pooled connection before failing with
|
||||
* {@code ConnectionRequestTimeoutException}; unset keeps httpclient5's own default (3 minutes).
|
||||
*/
|
||||
public Builder connectionRequestTimeout(Duration value) {
|
||||
this.connectionRequestTimeout = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FlociDockerHttpClient build() {
|
||||
Objects.requireNonNull(dockerHost, "dockerHost");
|
||||
return new FlociDockerHttpClient(dockerHost, sslConfig, maxConnections, connectionTimeout, responseTimeout);
|
||||
return new FlociDockerHttpClient(dockerHost, sslConfig, maxConnections, connectionTimeout, responseTimeout,
|
||||
connectionRequestTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user