diff --git a/s3stream/src/main/java/com/automq/stream/s3/cache/StreamReader.java b/s3stream/src/main/java/com/automq/stream/s3/cache/StreamReader.java index 013868f65..83114090f 100644 --- a/s3stream/src/main/java/com/automq/stream/s3/cache/StreamReader.java +++ b/s3stream/src/main/java/com/automq/stream/s3/cache/StreamReader.java @@ -422,14 +422,14 @@ CompletableFuture getDataBlockIndices(long streamId, long endOffset, ReadC } private void completeInflightTask(DefaultS3BlockCache.ReadAheadTaskKey key, Throwable ex) { - inflightReadAheadTaskMap.computeIfPresent(key, (k, v) -> { + CompletableFuture cf = inflightReadAheadTaskMap.remove(key); + if (cf != null) { if (ex != null) { - v.completeExceptionally(ex); + cf.completeExceptionally(ex); } else { - v.complete(null); + cf.complete(null); } - return null; - }); + } } private List> collectStreamDataBlocksToRead(ReadContext context) {