Browse Source

Add doOnDiscard hook for streaming mode

Potential fix for issue reported at
https://github.com/reactor/reactor-netty/issues/1746
pull/27278/head
Rossen Stoyanchev 3 years ago
parent
commit
77a562dfee
  1. 12
      spring-web/src/main/java/org/springframework/http/codec/EncoderHttpMessageWriter.java

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

@ -141,16 +141,18 @@ public class EncoderHttpMessageWriter<T> implements HttpMessageWriter<T> { @@ -141,16 +141,18 @@ public class EncoderHttpMessageWriter<T> implements HttpMessageWriter<T> {
}
if (isStreamingMediaType(contentType)) {
return message.writeAndFlushWith(body.map(buffer -> {
Hints.touchDataBuffer(buffer, hints, logger);
return Mono.just(buffer).doOnDiscard(PooledDataBuffer.class, DataBufferUtils::release);
}));
return message
.writeAndFlushWith(body.map(buffer -> {
Hints.touchDataBuffer(buffer, hints, logger);
return Mono.just(buffer).doOnDiscard(PooledDataBuffer.class, DataBufferUtils::release);
}))
.doOnDiscard(PooledDataBuffer.class, DataBufferUtils::release);
}
if (logger.isDebugEnabled()) {
body = body.doOnNext(buffer -> Hints.touchDataBuffer(buffer, hints, logger));
}
return message.writeWith(body);
return message.writeWith(body).doOnDiscard(PooledDataBuffer.class, DataBufferUtils::release);
}
@Nullable

Loading…
Cancel
Save