Skip to content

Commit f9e755f

Browse files
original-brownbearjasontedor
authored andcommitted
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
1 parent 827ba7f commit f9e755f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpRequestHandler.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,15 @@ protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Except
6464
Unpooled.copiedBuffer(request.content()),
6565
request.headers(),
6666
request.trailingHeaders());
67-
final Netty4HttpRequest httpRequest = new Netty4HttpRequest(serverTransport.xContentRegistry, copy, ctx.channel());
67+
final Netty4HttpRequest httpRequest;
68+
try {
69+
httpRequest = new Netty4HttpRequest(serverTransport.xContentRegistry, copy, ctx.channel());
70+
} catch (Exception ex) {
71+
if (pipelinedRequest != null) {
72+
pipelinedRequest.release();
73+
}
74+
throw ex;
75+
}
6876
final Netty4HttpChannel channel =
6977
new Netty4HttpChannel(serverTransport, httpRequest, pipelinedRequest, detailedErrorsEnabled, threadContext);
7078

0 commit comments

Comments
 (0)