aboutsummaryrefslogtreecommitdiffstats
path: root/vespa-feed-client
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2021-05-18 16:28:58 +0200
committerJon Marius Venstad <venstad@gmail.com>2021-05-18 16:28:58 +0200
commit7c5d7415e423dbfed3e5a893e9b161217a18b81e (patch)
treee32e48c79f0b30d5941aa82615d839fb19264a85 /vespa-feed-client
parent8bf0c34f48471825ce15666893c1282ae6e5a1c0 (diff)
Wrap dispatch in case it throws, so future gets the exception
Diffstat (limited to 'vespa-feed-client')
-rw-r--r--vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/HttpFeedClient.java3
-rw-r--r--vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/HttpRequestStrategy.java10
2 files changed, 9 insertions, 4 deletions
diff --git a/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/HttpFeedClient.java b/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/HttpFeedClient.java
index 236ba984114..39fcfd45a6f 100644
--- a/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/HttpFeedClient.java
+++ b/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/HttpFeedClient.java
@@ -115,7 +115,8 @@ class HttpFeedClient implements FeedClient {
return send("DELETE", documentId, null, params);
}
- @Override public void close() throws IOException {
+ @Override
+ public void close() throws IOException {
if ( ! closed.getAndSet(true))
httpClient.close();
}
diff --git a/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/HttpRequestStrategy.java b/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/HttpRequestStrategy.java
index 1fef67dda56..7d6571a3e6c 100644
--- a/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/HttpRequestStrategy.java
+++ b/vespa-feed-client/src/main/java/com/yahoo/vespa/feed/client/HttpRequestStrategy.java
@@ -135,10 +135,14 @@ class HttpRequestStrategy implements RequestStrategy<SimpleHttpResponse>, HttpRe
public CompletableFuture<SimpleHttpResponse> enqueue(DocumentId documentId, Consumer<CompletableFuture<SimpleHttpResponse>> dispatch) {
acquireSlot();
+ Consumer<CompletableFuture<SimpleHttpResponse>> safeDispatch = vessel -> {
+ try { dispatch.accept(vessel); }
+ catch (Throwable t) { vessel.completeExceptionally(t); }
+ };
CompletableFuture<SimpleHttpResponse> vessel = new CompletableFuture<>();
- byId.compute(documentId, (id, previous) -> { // TODO; consider merging with above locking.
- if (previous == null) dispatch.accept(vessel);
- else previous.whenComplete((__, ___) -> dispatch.accept(vessel)); // TODO: keep a list so we can empty it?
+ byId.compute(documentId, (id, previous) -> {
+ if (previous == null) safeDispatch.accept(vessel);
+ else previous.whenComplete((__, ___) -> safeDispatch.accept(vessel));
return vessel;
});