tolbertam commented on code in PR #2003:
URL:
https://github.com/apache/cassandra-java-driver/pull/2003#discussion_r1938355943
##########
core/src/main/java/com/datastax/oss/driver/internal/core/cql/CqlPrepareAsyncProcessor.java:
##########
@@ -141,25 +195,23 @@ public CompletionStage<PreparedStatement> process(
String sessionLogPrefix) {
try {
- CompletableFuture<PreparedStatement> result =
cache.getIfPresent(request);
- if (result == null) {
- CompletableFuture<PreparedStatement> mine = new CompletableFuture<>();
- result = cache.get(request, () -> mine);
- if (result == mine) {
- new CqlPrepareHandler(request, session, context, sessionLogPrefix)
- .handle()
- .whenComplete(
- (preparedStatement, error) -> {
- if (error != null) {
- mine.completeExceptionally(error);
- cache.invalidate(request); // Make sure failure isn't
cached indefinitely
- } else {
- mine.complete(preparedStatement);
- }
- });
- }
- }
- return result;
+ CompletableFuture<PreparedStatement> rv = new CompletableFuture<>();
Review Comment:
Another possible concern here: Futures get added in `process` which will be
handled in the application threads, while `whenComplete` gets handled in an
`io` thread. I think even fixing the issue above, technically without
additional coordination/synchronization you could have a race where a new
Future gets added in `process` but never gets marked completed in
`whenComplete`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]