Skip to content

Commit 28e206a

Browse files
committed
Apply doOnDiscard for streaming mode
Use of Flux.just is problematic in that if the Flux is cancelled before demand, the item may never be read, nor freed. Flux#just does not even delegate cancellation signals. Closes gh-22731
1 parent b11e7fe commit 28e206a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

spring-web/src/main/java/org/springframework/http/codec/EncoderHttpMessageWriter.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,13 @@ public Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType eleme
131131
});
132132
}
133133

134-
return (isStreamingMediaType(contentType) ?
135-
message.writeAndFlushWith(body.map(Flux::just)) : message.writeWith(body));
134+
if (isStreamingMediaType(contentType)) {
135+
return message.writeAndFlushWith(body.map(buffer ->
136+
Mono.fromCallable(() -> buffer)
137+
.doOnDiscard(PooledDataBuffer.class, PooledDataBuffer::release)));
138+
}
139+
140+
return message.writeWith(body);
136141
}
137142

138143
@Nullable

0 commit comments

Comments
 (0)