Skip to content

Commit

Permalink
Release pipelined request in netty server tests (#32368)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Tim-Brooks authored Jul 25, 2018
1 parent bb10c8a commit 80d67ae
Showing 1 changed file with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Expand Down

0 comments on commit 80d67ae

Please sign in to comment.