Skip to content

Commit

Permalink
fix(server): Use default value of Connection Pool when property is no…
Browse files Browse the repository at this point in the history
…t set (#494)

closes #491

(cherry picked from commit 3200200)
  • Loading branch information
NiccoMlt committed Sep 10, 2024
1 parent 57f4482 commit e82dea2
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@

import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.summingInt;
import static org.carapaceproxy.server.config.ConnectionPoolConfiguration.DEFAULT_BORROW_TIMEOUT;
import static org.carapaceproxy.server.config.ConnectionPoolConfiguration.DEFAULT_CONNECT_TIMEOUT;
import static org.carapaceproxy.server.config.ConnectionPoolConfiguration.DEFAULT_DISPOSE_TIMEOUT;
import static org.carapaceproxy.server.config.ConnectionPoolConfiguration.DEFAULT_IDLE_TIMEOUT;
import static org.carapaceproxy.server.config.ConnectionPoolConfiguration.DEFAULT_KEEPALIVE;
import static org.carapaceproxy.server.config.ConnectionPoolConfiguration.DEFAULT_KEEPALIVE_COUNT;
import static org.carapaceproxy.server.config.ConnectionPoolConfiguration.DEFAULT_KEEPALIVE_IDLE;
import static org.carapaceproxy.server.config.ConnectionPoolConfiguration.DEFAULT_KEEPALIVE_INTERVAL;
import static org.carapaceproxy.server.config.ConnectionPoolConfiguration.DEFAULT_MAX_CONNECTIONS_PER_ENDPOINT;
import static org.carapaceproxy.server.config.ConnectionPoolConfiguration.DEFAULT_MAX_LIFETIME;
import static org.carapaceproxy.server.config.ConnectionPoolConfiguration.DEFAULT_STUCK_REQUEST_TIMEOUT;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -67,17 +78,17 @@ public static final class ConnectionPoolBean {

private String id;
private String domain;
private int maxConnectionsPerEndpoint;
private int borrowTimeout;
private int connectTimeout;
private int stuckRequestTimeout;
private int idleTimeout;
private int maxLifeTime;
private int disposeTimeout;
private int keepaliveIdle;
private int keepaliveInterval;
private int keepaliveCount;
private boolean keepAlive;
private int maxConnectionsPerEndpoint = DEFAULT_MAX_CONNECTIONS_PER_ENDPOINT;
private int borrowTimeout = DEFAULT_BORROW_TIMEOUT;
private int connectTimeout = DEFAULT_CONNECT_TIMEOUT;
private int stuckRequestTimeout = DEFAULT_STUCK_REQUEST_TIMEOUT;
private int idleTimeout = DEFAULT_IDLE_TIMEOUT;
private int maxLifeTime = DEFAULT_MAX_LIFETIME;
private int disposeTimeout = DEFAULT_DISPOSE_TIMEOUT;
private int keepaliveIdle = DEFAULT_KEEPALIVE_IDLE;
private int keepaliveInterval = DEFAULT_KEEPALIVE_INTERVAL;
private int keepaliveCount = DEFAULT_KEEPALIVE_COUNT;
private boolean keepAlive = DEFAULT_KEEPALIVE;
private boolean enabled;

private int totalConnections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@

import static org.carapaceproxy.server.certificates.DynamicCertificatesManager.DEFAULT_DAYS_BEFORE_RENEWAL;
import static org.carapaceproxy.server.certificates.DynamicCertificatesManager.DEFAULT_KEYPAIRS_SIZE;
import static org.carapaceproxy.server.config.ConnectionPoolConfiguration.DEFAULT_BORROW_TIMEOUT;
import static org.carapaceproxy.server.config.ConnectionPoolConfiguration.DEFAULT_CONNECT_TIMEOUT;
import static org.carapaceproxy.server.config.ConnectionPoolConfiguration.DEFAULT_DISPOSE_TIMEOUT;
import static org.carapaceproxy.server.config.ConnectionPoolConfiguration.DEFAULT_IDLE_TIMEOUT;
import static org.carapaceproxy.server.config.ConnectionPoolConfiguration.DEFAULT_KEEPALIVE;
import static org.carapaceproxy.server.config.ConnectionPoolConfiguration.DEFAULT_KEEPALIVE_COUNT;
import static org.carapaceproxy.server.config.ConnectionPoolConfiguration.DEFAULT_KEEPALIVE_IDLE;
import static org.carapaceproxy.server.config.ConnectionPoolConfiguration.DEFAULT_KEEPALIVE_INTERVAL;
import static org.carapaceproxy.server.config.ConnectionPoolConfiguration.DEFAULT_MAX_CONNECTIONS_PER_ENDPOINT;
import static org.carapaceproxy.server.config.ConnectionPoolConfiguration.DEFAULT_MAX_LIFETIME;
import static org.carapaceproxy.server.config.ConnectionPoolConfiguration.DEFAULT_STUCK_REQUEST_TIMEOUT;
import static org.carapaceproxy.server.config.NetworkListenerConfiguration.DEFAULT_FORWARDED_STRATEGY;
import static org.carapaceproxy.server.config.NetworkListenerConfiguration.DEFAULT_SSL_PROTOCOLS;
import static org.carapaceproxy.server.filters.RequestFilterFactory.buildRequestFilter;
Expand Down Expand Up @@ -63,20 +74,20 @@ public class RuntimeServerConfiguration {
private final Map<String, ConnectionPoolConfiguration> connectionPools = new HashMap<>();
private ConnectionPoolConfiguration defaultConnectionPool;

private int maxConnectionsPerEndpoint = 10;
private int idleTimeout = 60_000;
private int maxLifeTime = 100_000;
private int stuckRequestTimeout = 120_000;
private int maxConnectionsPerEndpoint = DEFAULT_MAX_CONNECTIONS_PER_ENDPOINT;
private int idleTimeout = DEFAULT_IDLE_TIMEOUT;
private int maxLifeTime = DEFAULT_MAX_LIFETIME;
private int stuckRequestTimeout = DEFAULT_STUCK_REQUEST_TIMEOUT;
private boolean backendsUnreachableOnStuckRequests = false;
private int connectTimeout = 10_000;
private int borrowTimeout = 60_000;
private int disposeTimeout = 300_000; // 5 min;
private int connectTimeout = DEFAULT_CONNECT_TIMEOUT;
private int borrowTimeout = DEFAULT_BORROW_TIMEOUT;
private int disposeTimeout = DEFAULT_DISPOSE_TIMEOUT; // 5 min
private int soBacklog = 128;
private int keepaliveIdle = 300; // sec
private int keepaliveInterval = 60; // sec
private int keepaliveCount = 8;
private boolean clientKeepAlive = true;
private boolean serverKeepAlive = true;
private int keepaliveIdle = DEFAULT_KEEPALIVE_IDLE; // sec
private int keepaliveInterval = DEFAULT_KEEPALIVE_INTERVAL; // sec
private int keepaliveCount = DEFAULT_KEEPALIVE_COUNT;
private boolean clientKeepAlive = DEFAULT_KEEPALIVE;
private boolean serverKeepAlive = DEFAULT_KEEPALIVE;
private int maxKeepAliveRequests = 1000;
private long cacheMaxSize = 0;
private long cacheMaxFileSize = 0;
Expand All @@ -90,7 +101,7 @@ public class RuntimeServerConfiguration {
+ "time t=<total_time>ms b=<backend_time>ms, protocol=<http_protocol_version>";
private int accessLogMaxQueueCapacity = 2000;
private int accessLogFlushInterval = 5000;
private int accessLogWaitBetweenFailures = 10000;
private int accessLogWaitBetweenFailures = DEFAULT_CONNECT_TIMEOUT;
private long accessLogMaxSize = 524288000;
private boolean accessLogAdvancedEnabled = false;
private int accessLogAdvancedBodySize = 1_000; // bytes
Expand All @@ -113,7 +124,7 @@ public class RuntimeServerConfiguration {
private boolean http10BackwardCompatibilityEnabled = false;
private String localCertificatesStorePath;
private Set<String> localCertificatesStorePeersIds;
private int maxAttempts = 10;
private int maxAttempts = DEFAULT_MAX_CONNECTIONS_PER_ENDPOINT;
private Set<String> alwaysCachedExtensions = Set.of("png", "gif", "jpg", "jpeg", "js", "css", "woff2", "webp");

public RuntimeServerConfiguration() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,39 @@

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
* Configuration of a single connection pool
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ConnectionPoolConfiguration {
public static final int DEFAULT_MAX_CONNECTIONS_PER_ENDPOINT = 10;
public static final int DEFAULT_IDLE_TIMEOUT = 60_000;
public static final int DEFAULT_BORROW_TIMEOUT = 60_000;
public static final int DEFAULT_MAX_LIFETIME = 100_000;
public static final int DEFAULT_STUCK_REQUEST_TIMEOUT = 120_000;
public static final int DEFAULT_CONNECT_TIMEOUT = 10_000;
public static final int DEFAULT_DISPOSE_TIMEOUT = 300_000;
public static final int DEFAULT_KEEPALIVE_IDLE = 300;
public static final int DEFAULT_KEEPALIVE_INTERVAL = 60;
public static final int DEFAULT_KEEPALIVE_COUNT = 8;
public static final boolean DEFAULT_KEEPALIVE = true;

private String id;
private String domain;
private int maxConnectionsPerEndpoint;
private int borrowTimeout;
private int connectTimeout;
private int stuckRequestTimeout;
private int idleTimeout;
private int maxLifeTime;
private int disposeTimeout;
private int keepaliveIdle;
private int keepaliveInterval;
private int keepaliveCount;
private boolean keepAlive;

private int maxConnectionsPerEndpoint = DEFAULT_MAX_CONNECTIONS_PER_ENDPOINT;
private int borrowTimeout = DEFAULT_BORROW_TIMEOUT;
private int connectTimeout = DEFAULT_CONNECT_TIMEOUT;
private int stuckRequestTimeout = DEFAULT_STUCK_REQUEST_TIMEOUT;
private int idleTimeout = DEFAULT_IDLE_TIMEOUT;
private int maxLifeTime = DEFAULT_MAX_LIFETIME;
private int disposeTimeout = DEFAULT_DISPOSE_TIMEOUT;
private int keepaliveIdle = DEFAULT_KEEPALIVE_IDLE;
private int keepaliveInterval = DEFAULT_KEEPALIVE_INTERVAL;
private int keepaliveCount = DEFAULT_KEEPALIVE_COUNT;
private boolean keepAlive = DEFAULT_KEEPALIVE;
private boolean enabled;

}

0 comments on commit e82dea2

Please sign in to comment.