diff options
author | Jon Marius Venstad <venstad@gmail.com> | 2021-12-14 10:17:50 +0100 |
---|---|---|
committer | Jon Marius Venstad <venstad@gmail.com> | 2021-12-14 10:17:50 +0100 |
commit | ab9c36d5eba9fe469d7e1f6e0c075ace0cb3c1fe (patch) | |
tree | 9fb7569e8670278efdb0dc8bd3425b712dedd019 /vespa-feed-client/src/main | |
parent | b216e35423ec9784e493b89b9b85bab9f6468e23 (diff) |
Use user specified timeout for client timeout as well
Diffstat (limited to 'vespa-feed-client/src/main')
3 files changed, 12 insertions, 3 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 8233a1773f5..1874bd42e16 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 @@ -83,7 +83,8 @@ class ApacheCluster implements Cluster { @Override public void failed(Exception ex) { vessel.completeExceptionally(ex); } @Override public void cancelled() { vessel.cancel(false); } }); - Future<?> cancellation = executor.schedule(() -> { future.cancel(true); vessel.cancel(true); }, 200, TimeUnit.SECONDS); + long timeoutMillis = wrapped.timeout() == null ? 200_000 : wrapped.timeout().toMillis() * 11 / 10 + 1_000; + Future<?> cancellation = executor.schedule(() -> { future.cancel(true); vessel.cancel(true); }, timeoutMillis, TimeUnit.MILLISECONDS); vessel.whenComplete((__, ___) -> cancellation.cancel(true)); } catch (Throwable thrown) { diff --git a/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/HttpFeedClient.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/HttpFeedClient.java index 3fd44596d63..c136d697a0b 100644 --- a/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/HttpFeedClient.java +++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/HttpFeedClient.java @@ -92,7 +92,8 @@ class HttpFeedClient implements FeedClient { HttpRequest request = new HttpRequest(method, getPath(documentId) + getQuery(params), requestHeaders, - operationJson == null ? null : operationJson.getBytes(UTF_8)); // TODO: make it bytes all the way? + operationJson == null ? null : operationJson.getBytes(UTF_8), // TODO: make it bytes all the way? + params.timeout().orElse(null)); CompletableFuture<Result> promise = new CompletableFuture<>(); requestStrategy.enqueue(documentId, request) diff --git a/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/HttpRequest.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/HttpRequest.java index 08b8ca08c61..0ad7b82347e 100644 --- a/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/HttpRequest.java +++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/HttpRequest.java @@ -1,6 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package ai.vespa.feed.client.impl; +import java.time.Duration; import java.util.Map; import java.util.function.Supplier; @@ -10,12 +11,14 @@ class HttpRequest { private final String path; private final Map<String, Supplier<String>> headers; private final byte[] body; + private final Duration timeout; - public HttpRequest(String method, String path, Map<String, Supplier<String>> headers, byte[] body) { + public HttpRequest(String method, String path, Map<String, Supplier<String>> headers, byte[] body, Duration timeout) { this.method = method; this.path = path; this.headers = headers; this.body = body; + this.timeout = timeout; } public String method() { @@ -34,6 +37,10 @@ class HttpRequest { return body; } + public Duration timeout() { + return timeout; + } + @Override public String toString() { return method + " " + path; |