From fa6162bb77bbabc63c1d93009841b0c49e8c8e92 Mon Sep 17 00:00:00 2001 From: sebthom Date: Fri, 31 Oct 2025 19:50:15 +0100 Subject: [PATCH] fix(jsonrpc): cancel locally first and still emit $/cancelRequest once - Prevent a race where a server's RequestCancelled response completes the future with ResponseErrorException before local cancellation, breaking expected CancellationException behavior. - Change cancel(boolean) to cancel the future locally first, then (root-only) send $/cancelRequest. - Adjust cancelRequest() to emit once even if the future is already completed locally by removing the isDone() short-circuit; dedup remains via cancelSent. --- .../eclipse/lsp4j/jsonrpc/JsonRpcRequestFuture.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/JsonRpcRequestFuture.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/JsonRpcRequestFuture.java index 45a1c9bd..3d7e9ca4 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/JsonRpcRequestFuture.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/JsonRpcRequestFuture.java @@ -93,16 +93,18 @@ public JsonRpcRequestFuture applyToEitherAsync(final CompletionStage getRoot() { */ public boolean cancelRequest() { final JsonRpcRequestFuture root = getRoot(); - if (root.isDone()) { - return false; - } if (root.cancelSent.compareAndSet(false, true)) { root.cancelAction.run(); return true;