Fix buffer leak in AbstractServerHttpResponse

See gh-26232
This commit is contained in:
Rossen Stoyanchev
2020-12-07 22:28:45 +00:00
parent ad42010785
commit 7418c4b7b7
2 changed files with 39 additions and 3 deletions

View File

@@ -211,9 +211,16 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse {
// We must resolve value first however, for a chance to handle potential error.
if (body instanceof Mono) {
return ((Mono<? extends DataBuffer>) body)
.flatMap(buffer -> doCommit(() ->
writeWithInternal(Mono.fromCallable(() -> buffer)
.doOnDiscard(PooledDataBuffer.class, DataBufferUtils::release))))
.flatMap(buffer ->
doCommit(() -> {
try {
return writeWithInternal(Mono.fromCallable(() -> buffer)
.doOnDiscard(PooledDataBuffer.class, DataBufferUtils::release));
}
catch (Throwable ex) {
return Mono.error(ex);
}
}).doOnError(ex -> DataBufferUtils.release(buffer)))
.doOnError(t -> getHeaders().clearContentHeaders());
}
else {