From 80d67ae0b47dd3ea4fdd3016273f0ae5bd878425 Mon Sep 17 00:00:00 2001 From: Tim Brooks Date: Wed, 25 Jul 2018 14:39:44 -0600 Subject: [PATCH] Release pipelined request in netty server tests (#32368) 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. --- .../Netty4HttpServerPipeliningTests.java | 56 ++++++++++--------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/modules/transport-netty4/src/test/java/org/elasticsearch/http/netty4/Netty4HttpServerPipeliningTests.java b/modules/transport-netty4/src/test/java/org/elasticsearch/http/netty4/Netty4HttpServerPipeliningTests.java index 4f96f185a8abf..77f8ec29db514 100644 --- a/modules/transport-netty4/src/test/java/org/elasticsearch/http/netty4/Netty4HttpServerPipeliningTests.java +++ b/modules/transport-netty4/src/test/java/org/elasticsearch/http/netty4/Netty4HttpServerPipeliningTests.java @@ -240,37 +240,43 @@ class PossiblySlowRunnable implements Runnable { @Override public void run() { - final String uri; - if (pipelinedRequest != null && pipelinedRequest.last() instanceof FullHttpRequest) { - uri = ((FullHttpRequest) pipelinedRequest.last()).uri(); - } else { - uri = fullHttpRequest.uri(); - } + try { + final String uri; + if (pipelinedRequest != null && pipelinedRequest.last() instanceof FullHttpRequest) { + uri = ((FullHttpRequest) pipelinedRequest.last()).uri(); + } else { + uri = fullHttpRequest.uri(); + } - final ByteBuf buffer = Unpooled.copiedBuffer(uri, StandardCharsets.UTF_8); + final ByteBuf buffer = Unpooled.copiedBuffer(uri, StandardCharsets.UTF_8); - final DefaultFullHttpResponse httpResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, buffer); - httpResponse.headers().add(HttpHeaderNames.CONTENT_LENGTH, buffer.readableBytes()); + 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+"); - if (slow) { - try { - Thread.sleep(scaledRandomIntBetween(500, 1000)); - } catch (InterruptedException e) { - throw new RuntimeException(e); + final boolean slow = uri.matches("/slow/\\d+"); + if (slow) { + try { + Thread.sleep(scaledRandomIntBetween(500, 1000)); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } else { + assert uri.matches("/\\d+"); } - } else { - assert uri.matches("/\\d+"); - } - final ChannelPromise promise = ctx.newPromise(); - final Object msg; - if (pipelinedRequest != null) { - msg = pipelinedRequest.createHttpResponse(httpResponse, promise); - } else { - msg = httpResponse; + final ChannelPromise promise = ctx.newPromise(); + final Object msg; + if (pipelinedRequest != null) { + msg = pipelinedRequest.createHttpResponse(httpResponse, promise); + } else { + msg = httpResponse; + } + ctx.writeAndFlush(msg, promise); + } finally { + if (pipelinedRequest != null) { + pipelinedRequest.release(); + } } - ctx.writeAndFlush(msg, promise); } }