Skip to content

Commit eac7b24

Browse files
lucboutierabsurdfarce
authored andcommitted
JAVA-3055: Prevent PreparedStatement cache to be polluted if a request is cancelled.
There was a critical issue when the external code cancels a request, indeed the cached CompletableFuture will then always throw a CancellationException. This may happens, for example, when used by reactive like Mono.zip or Mono.firstWithValue. patch by Luc Boutier; reviewed by Alexandre Dutra and Bret McGuire reference: #1757
1 parent 04d34a8 commit eac7b24

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

core/src/main/java/com/datastax/oss/driver/internal/core/cql/CqlPrepareAsyncProcessor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ public CompletionStage<PreparedStatement> process(
159159
});
160160
}
161161
}
162-
return result;
162+
// Return a defensive copy. So if a client cancels its request, the cache won't be impacted
163+
// nor a potential concurrent request.
164+
return result.thenApply(x -> x); // copy() is available only since Java 9
163165
} catch (ExecutionException e) {
164166
return CompletableFutures.failedFuture(e.getCause());
165167
}

0 commit comments

Comments
 (0)