Release Pooled Buffers Earlier for HTTP Requests (#44952) (#44991)

* We should release the buffers right after copying and not only do so after we did all the request handling on the copy
* Relates #44564
This commit is contained in:
Armin Braun 2019-07-30 10:30:01 +02:00 committed by GitHub
parent f575370e2f
commit 4495140d1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 38 deletions

View File

@ -41,9 +41,9 @@ class Netty4HttpRequestHandler extends SimpleChannelInboundHandler<HttpPipelined
protected void channelRead0(ChannelHandlerContext ctx, HttpPipelinedRequest<FullHttpRequest> msg) {
Netty4HttpChannel channel = ctx.channel().attr(Netty4HttpServerTransport.HTTP_CHANNEL_KEY).get();
FullHttpRequest request = msg.getRequest();
final FullHttpRequest copiedRequest;
try {
final FullHttpRequest copiedRequest =
copiedRequest =
new DefaultFullHttpRequest(
request.protocolVersion(),
request.method(),
@ -51,7 +51,10 @@ class Netty4HttpRequestHandler extends SimpleChannelInboundHandler<HttpPipelined
Unpooled.copiedBuffer(request.content()),
request.headers(),
request.trailingHeaders());
} finally {
// As we have copied the buffer, we can release the request
request.release();
}
Netty4HttpRequest httpRequest = new Netty4HttpRequest(copiedRequest, msg.getSequence());
if (request.decoderResult().isFailure()) {
@ -65,10 +68,6 @@ class Netty4HttpRequestHandler extends SimpleChannelInboundHandler<HttpPipelined
} else {
serverTransport.incomingRequest(httpRequest, channel);
}
} finally {
// As we have copied the buffer, we can release the request
request.release();
}
}
@Override

View File

@ -159,16 +159,19 @@ public class HttpReadWriteHandler implements NioChannelHandler {
final HttpPipelinedRequest<FullHttpRequest> pipelinedRequest = (HttpPipelinedRequest<FullHttpRequest>) msg;
FullHttpRequest request = pipelinedRequest.getRequest();
final FullHttpRequest copiedRequest;
try {
final FullHttpRequest copiedRequest =
new DefaultFullHttpRequest(
copiedRequest = new DefaultFullHttpRequest(
request.protocolVersion(),
request.method(),
request.uri(),
Unpooled.copiedBuffer(request.content()),
request.headers(),
request.trailingHeaders());
} finally {
// As we have copied the buffer, we can release the request
request.release();
}
NioHttpRequest httpRequest = new NioHttpRequest(copiedRequest, pipelinedRequest.getSequence());
if (request.decoderResult().isFailure()) {
@ -182,10 +185,6 @@ public class HttpReadWriteHandler implements NioChannelHandler {
} else {
transport.incomingRequest(httpRequest, nioHttpChannel);
}
} finally {
// As we have copied the buffer, we can release the request
request.release();
}
}
private void maybeReadTimeout() {