From 06b0f51741c4e60fbe8ea91009706fbf0a334d25 Mon Sep 17 00:00:00 2001 From: Martynas Date: Wed, 27 Nov 2024 23:59:54 +0100 Subject: [PATCH] Unset `CONNECT_TIMEOUT` Set `setValidateAfterInactivity()` to 5 seconds (same as Varnish's `idle_timeout`) --- src/main/java/com/atomgraph/linkeddatahub/Application.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/atomgraph/linkeddatahub/Application.java b/src/main/java/com/atomgraph/linkeddatahub/Application.java index ba9b45c65..913a4c463 100644 --- a/src/main/java/com/atomgraph/linkeddatahub/Application.java +++ b/src/main/java/com/atomgraph/linkeddatahub/Application.java @@ -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()); @@ -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()); @@ -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());