Fixed byte buffer leak in Netty4 request handler

If creating the REST request throws an exception (for example, because
of invalid headers), we leak the request due to failure to release the
buffer (which would otherwise happen after replying on the
channel). This commit addresses this leak by handling the failure case.

Relates #27222
This commit is contained in:
Armin Braun 2017-11-03 01:22:19 +01:00 committed by Jason Tedor
parent 827ba7f82d
commit f9e755f980
1 changed files with 9 additions and 1 deletions

View File

@ -64,7 +64,15 @@ class Netty4HttpRequestHandler extends SimpleChannelInboundHandler<Object> {
Unpooled.copiedBuffer(request.content()),
request.headers(),
request.trailingHeaders());
final Netty4HttpRequest httpRequest = new Netty4HttpRequest(serverTransport.xContentRegistry, copy, ctx.channel());
final Netty4HttpRequest httpRequest;
try {
httpRequest = new Netty4HttpRequest(serverTransport.xContentRegistry, copy, ctx.channel());
} catch (Exception ex) {
if (pipelinedRequest != null) {
pipelinedRequest.release();
}
throw ex;
}
final Netty4HttpChannel channel =
new Netty4HttpChannel(serverTransport, httpRequest, pipelinedRequest, detailedErrorsEnabled, threadContext);