Skip to content

Commit

Permalink
Unset CONNECT_TIMEOUT
Browse files Browse the repository at this point in the history
Set `setValidateAfterInactivity()` to 5 seconds (same as Varnish's `idle_timeout`)
  • Loading branch information
namedgraph committed Nov 27, 2024
1 parent c52cc8a commit 06b0f51
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/java/com/atomgraph/linkeddatahub/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,8 @@ public static Client getClient(KeyStore keyStore, String keyStorePassword, KeySt
if (keyStore == null) throw new IllegalArgumentException("KeyStore cannot be null");
if (keyStorePassword == null) throw new IllegalArgumentException("KeyStore password string cannot be null");
if (trustStore == null) throw new IllegalArgumentException("KeyStore (truststore) cannot be null");

Integer connIdleTimeout = 5000;

// for client authentication
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(keyStore, keyStorePassword.toCharArray());
Expand Down Expand Up @@ -1384,6 +1385,8 @@ public void releaseConnection(final HttpClientConnection managedConn, final Obje
};
if (maxConnPerRoute != null) conman.setDefaultMaxPerRoute(maxConnPerRoute);
if (maxTotalConn != null) conman.setMaxTotal(maxTotalConn);
conman.setValidateAfterInactivity(connIdleTimeout); // check connections idle for more than Varnish's idle_timeout which is 5s
//conman.closeIdleConnections(connIdleTimeout, TimeUnit.MILLISECONDS); // match the Varnish idle timeout

ClientConfig config = new ClientConfig();
config.connectorProvider(new ApacheConnectorProvider());
Expand All @@ -1394,7 +1397,7 @@ public void releaseConnection(final HttpClientConnection managedConn, final Obje
config.register(new QueryProvider());
config.register(new UpdateRequestProvider());
config.property(ClientProperties.FOLLOW_REDIRECTS, true);
config.property(ClientProperties.CONNECT_TIMEOUT, 1000);
//config.property(ClientProperties.CONNECT_TIMEOUT, 1000);
config.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.BUFFERED); // https://stackoverflow.com/questions/42139436/jersey-client-throws-cannot-retry-request-with-a-non-repeatable-request-entity
config.property(ApacheClientProperties.CONNECTION_MANAGER, conman);
//config.property(ApacheClientProperties.CONNECTION_CLOSING_STRATEGY, new ApacheConnectionClosingStrategy.GracefulClosingStrategy());
Expand Down

0 comments on commit 06b0f51

Please sign in to comment.