Release pipelined request in netty server tests
The Netty4HttpServerPipeliningTests adds a different request handler to
the netty pipeline. This request does not properly release pipelined
request. This means that when we enable leak detection, the test fails.
This commit properly releases the request.
@@ -240,6 +240,7 @@ public class Netty4HttpServerPipeliningTests extends ESTestCase {
@Override
public void run() {
+ try {
final String uri;
if (pipelinedRequest != null && pipelinedRequest.last() instanceof FullHttpRequest) {
uri = ((FullHttpRequest) pipelinedRequest.last()).uri();
@@ -249,7 +250,7 @@ public class Netty4HttpServerPipeliningTests extends ESTestCase {
final ByteBuf buffer = Unpooled.copiedBuffer(uri, StandardCharsets.UTF_8);
- final DefaultFullHttpResponse httpResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, buffer);
+ final FullHttpResponse httpResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, buffer);
httpResponse.headers().add(HttpHeaderNames.CONTENT_LENGTH, buffer.readableBytes());
final boolean slow = uri.matches("/slow/\\d+");
@@ -271,6 +272,11 @@ public class Netty4HttpServerPipeliningTests extends ESTestCase {
msg = httpResponse;
}
ctx.writeAndFlush(msg, promise);
+ } finally {
+ if (pipelinedRequest != null) {
+ pipelinedRequest.release();
+ }
+ }
}
}
