Skip to content

Commit 81f95ef

Browse files
committed
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
1 parent 9a1bba5 commit 81f95ef

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ public static Flux<DataBuffer> readAsynchronousFileChannel(Callable<Asynchronous
144144
channel -> Flux.create(sink -> {
145145
ReadCompletionHandler handler =
146146
new ReadCompletionHandler(channel, sink, position, bufferFactoryToUse, bufferSize);
147+
sink.onDispose(handler::dispose);
147148
DataBuffer dataBuffer = bufferFactoryToUse.allocateBuffer(bufferSize);
148149
ByteBuffer byteBuffer = dataBuffer.asByteBuffer(0, bufferSize);
149150
channel.read(byteBuffer, position, dataBuffer, handler);
150-
sink.onDispose(handler::dispose);
151151
}),
152152
channel -> {
153153
// Do not close channel from here, rather wait for the current read callback

0 commit comments

Comments
 (0)