From 74104ff2d355ac0186d6483b548cff1a4da1931c Mon Sep 17 00:00:00 2001 From: Michael Christen Date: Fri, 20 Jan 2023 20:22:14 +0100 Subject: [PATCH] fix to timeout --- source/net/yacy/cora/protocol/http/HTTPClient.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/source/net/yacy/cora/protocol/http/HTTPClient.java b/source/net/yacy/cora/protocol/http/HTTPClient.java index 063433518..d9e74baa9 100644 --- a/source/net/yacy/cora/protocol/http/HTTPClient.java +++ b/source/net/yacy/cora/protocol/http/HTTPClient.java @@ -132,7 +132,7 @@ public class HTTPClient implements Closeable { /** Default maximum time in seconds to keep alive an idle connection in the pool */ private static final int DEFAULT_POOLED_CONNECTION_TIME_TO_LIVE = 30; - private static final RequestConfig DFLTREQUESTCONFIG = initRequestConfig(); + private static RequestConfig DFLTREQUESTCONFIG = initRequestConfig(default_timeout); /** Use the custom YaCyDigestScheme for HTTP Digest Authentication */ private static final Lookup AUTHSCHEMEREGISTRY = RegistryBuilder.create() @@ -198,15 +198,15 @@ public class HTTPClient implements Closeable { setTimout(timeout); } - private static RequestConfig initRequestConfig() { + private static RequestConfig initRequestConfig(int timeout) { final RequestConfig.Builder builder = RequestConfig.custom(); // IMPORTANT - if not set to 'false' then servers do not process the request until a time-out of 2 seconds builder.setExpectContinueEnabled(false); // timeout in milliseconds until a connection is established in milliseconds - builder.setConnectionRequestTimeout(default_timeout); - builder.setConnectTimeout(default_timeout); + builder.setConnectionRequestTimeout(timeout); + builder.setConnectTimeout(timeout); // SO_TIMEOUT: maximum period inactivity between two consecutive data packets in milliseconds - builder.setSocketTimeout(default_timeout); + builder.setSocketTimeout(timeout); // ignore cookies, cause this may cause segfaults in default cookiestore and is not needed builder.setCookieSpec(CookieSpecs.IGNORE_COOKIES); builder.setRedirectsEnabled(true); @@ -265,7 +265,7 @@ public class HTTPClient implements Closeable { // Defines whether the socket can be bound even though a previous connection is still in a timeout state. .setSoReuseAddress(true) // SO_TIMEOUT: maximum period inactivity between two consecutive data packets in milliseconds - .setSoTimeout(3000) + .setSoTimeout(default_timeout) // conserve bandwidth by minimizing the number of segments that are sent .setTcpNoDelay(false) .build(); @@ -343,6 +343,7 @@ public class HTTPClient implements Closeable { this.reqConfBuilder.setSocketTimeout(timeout); this.reqConfBuilder.setConnectTimeout(timeout); this.reqConfBuilder.setConnectionRequestTimeout(timeout); + DFLTREQUESTCONFIG = initRequestConfig(timeout); } /**