diff options
author | Bjørn Christian Seime <bjorncs@yahooinc.com> | 2023-05-05 11:43:31 +0200 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@yahooinc.com> | 2023-05-05 11:43:31 +0200 |
commit | a0c329510540c3d426a30ce2ced826553d3fc1d5 (patch) | |
tree | 757e0af2b05cfd1603531a539bc2867036ac43e9 /vespa-feed-client | |
parent | 4c5a7673163caaaeeb33f8a0cc3489a6e4ade98b (diff) |
Manually handle response timeout
Diffstat (limited to 'vespa-feed-client')
-rw-r--r-- | vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/ApacheCluster.java | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/ApacheCluster.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/ApacheCluster.java index 7b17be1d2f0..f36178fb13a 100644 --- a/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/ApacheCluster.java +++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/ApacheCluster.java @@ -34,6 +34,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicInteger; import java.util.zip.GZIPOutputStream; @@ -85,12 +86,7 @@ class ApacheCluster implements Cluster { SimpleHttpRequest request = new SimpleHttpRequest(wrapped.method(), wrapped.path()); request.setScheme(endpoint.url.getScheme()); request.setAuthority(new URIAuthority(endpoint.url.getHost(), portOf(endpoint.url))); - long timeoutMillis = wrapped.timeout() == null ? 190_000 : wrapped.timeout().toMillis() * 11 / 10 + 1_000; - RequestConfig reqCfg = RequestConfig.custom() - .setConnectionRequestTimeout(Timeout.DISABLED) - .setResponseTimeout(Timeout.ofMilliseconds(timeoutMillis)) - .build(); - request.setConfig(reqCfg); + request.setConfig(RequestConfig.custom().setConnectionRequestTimeout(Timeout.DISABLED).build()); defaultHeaders.forEach(request::setHeader); wrapped.headers().forEach((name, value) -> request.setHeader(name, value.get())); if (wrapped.body() != null) { @@ -108,11 +104,15 @@ class ApacheCluster implements Cluster { @Override public void failed(Exception ex) { vessel.completeExceptionally(ex); } @Override public void cancelled() { vessel.cancel(false); } }); - // We've seen some requests time out, even with a response timeout, - // so we schedule this to be absolutely sure we don't hang (for ever). - Future<?> cancellation = timeoutExecutor.schedule(() -> { future.cancel(true); vessel.cancel(true); }, - timeoutMillis + 10_000, - TimeUnit.MILLISECONDS); + // Manually schedule response timeout as the Apache HTTP/2 multiplexing client does not support response timeouts + long timeoutMillis = wrapped.timeout() == null ? 190_000 : wrapped.timeout().toMillis(); + Future<?> cancellation = timeoutExecutor.schedule( + () -> { + vessel.completeExceptionally( + new TimeoutException(String.format("Request timed out after %dms", timeoutMillis))); + future.cancel(true); + }, + timeoutMillis * 11 / 10 + 1_000, TimeUnit.MILLISECONDS); vessel.whenComplete((__, ___) -> cancellation.cancel(true)); } catch (Throwable thrown) { |