Skip to content

Commit

Permalink
Fix the HTTP request body buffer is released by accident #1509
Browse files Browse the repository at this point in the history
* Fix the HTTP request body buffer is released by accident #1509

---------

Co-authored-by: zhaieryuan <[email protected]>
Co-authored-by: JamesChenX <[email protected]>
  • Loading branch information
3 people authored Jul 11, 2024
1 parent be72595 commit dbe9327
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,21 @@ private Object parseSingleValue(MethodParameterInfo parameter, @Nullable Object
*/
private Mono<Object> parseBody(HttpServerRequest request, @Nullable JavaType parameterType) {
return Mono.defer(() -> {
CompositeByteBuf body = Unpooled.compositeBuffer();
CompositeByteBuf body = Unpooled.compositeBuffer(
// Used to avoid the unnecessary consolidation/copy of buffers.
Integer.MAX_VALUE);
return request.receive()
// We don't use "collectList()" because we need to reject
// to receive buffers if it has exceeded the max size.
.doOnNext(buffer -> {
body.addComponent(true, buffer);
if (body.readableBytes() > maxBodySize) {
body.release();
if (body.readableBytes() + buffer.readableBytes() > maxBodySize) {
throw bodyTooLargeException;
}
// Retain once because the buffer will be released in
// "reactor.netty.channel.FluxReceive.onInboundNext" once the callback
// returns.
buffer.retain();
body.addComponent(true, buffer);
})
.then(Mono.defer(() -> {
int length = body.readableBytes();
Expand Down

0 comments on commit dbe9327

Please sign in to comment.