From 81f95efdbb7481a8a622648e7462b373597c762b Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Fri, 29 Mar 2019 15:43:06 -0400 Subject: [PATCH] Call onDispose before first read The cancellation callback in asynchronousReadFileChannel must be called before the first read I/O or otherwise if cancellation signals happens immediately the onDispose callback may be missed. The DefaultBufferFactory workaround however remains in place until an expected additional fix arrives with Reactor Core 3.2.9. See gh-22107 --- .../org/springframework/core/io/buffer/DataBufferUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferUtils.java b/spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferUtils.java index 4fa9beba58..af9015db6d 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferUtils.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferUtils.java @@ -144,10 +144,10 @@ public abstract class DataBufferUtils { channel -> Flux.create(sink -> { ReadCompletionHandler handler = new ReadCompletionHandler(channel, sink, position, bufferFactoryToUse, bufferSize); + sink.onDispose(handler::dispose); DataBuffer dataBuffer = bufferFactoryToUse.allocateBuffer(bufferSize); ByteBuffer byteBuffer = dataBuffer.asByteBuffer(0, bufferSize); channel.read(byteBuffer, position, dataBuffer, handler); - sink.onDispose(handler::dispose); }), channel -> { // Do not close channel from here, rather wait for the current read callback -- GitLab