Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,18 @@ public <U> JsonRpcRequestFuture<U> applyToEitherAsync(final CompletionStage<? ex

@Override
public boolean cancel(final boolean mayInterruptIfRunning) {
// Root cancel ensures cancelRequest() behavior once before local cancellation
// First cancel locally to ensure future is in a cancelled state
// before any concurrent response can complete it exceptionally.
final boolean cancelled = super.cancel(mayInterruptIfRunning);
// Only the root future should emit the protocol cancel notification.
if (root == this) {
try {
cancelRequest();
} catch (final RuntimeException ex) {
// catching potential exception to ensure local cancel still proceeds
LOG.log(Level.WARNING, ex.getMessage(), ex);
}
}
return super.cancel(mayInterruptIfRunning);
return cancelled;
}

/**
Expand All @@ -119,9 +121,6 @@ public JsonRpcRequestFuture<?> getRoot() {
*/
public boolean cancelRequest() {
final JsonRpcRequestFuture<?> root = getRoot();
if (root.isDone()) {
return false;
}
if (root.cancelSent.compareAndSet(false, true)) {
root.cancelAction.run();
return true;
Expand Down
Loading