HttpServerKeepAliveHandler doesn't correctly handle VoidChannelPromise

Motivation:

HttpServerKeepAliveHandler throws unexpected error when I do ctx.writeAndFlush(msg, ctx.voidPromise()); where msg is with header "Connection:close".

Modification:

HttpServerKeepAliveHandler does promise.unvoid() before adding close listener.

Result:

No error for VoidChannelPromise with HttpServerKeepAliveHandler. Fixes [#6698].
This commit is contained in:
Dmitriy Dumanskiy 2017-05-04 00:36:26 +03:00 committed by Norman Maurer
parent 464ae9fb7a
commit 174f4ea005
2 changed files with 29 additions and 1 deletions

View File

@ -82,7 +82,7 @@ public class HttpServerKeepAliveHandler extends ChannelDuplexHandler {
}
}
if (msg instanceof LastHttpContent && !shouldKeepAlive()) {
promise.addListener(ChannelFutureListener.CLOSE);
promise = promise.unvoid().addListener(ChannelFutureListener.CLOSE);
}
super.write(ctx, msg, promise);
}

View File

@ -117,6 +117,34 @@ public class HttpServerKeepAliveHandlerTest {
assertFalse(channel.finishAndReleaseAll());
}
@Test
public void testConnectionCloseHeaderHandledCorrectly() throws Exception {
HttpResponse response = new DefaultFullHttpResponse(httpVersion, responseStatus);
response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE);
setupMessageLength(response);
channel.writeAndFlush(response);
HttpResponse writtenResponse = channel.readOutbound();
assertFalse(channel.isOpen());
ReferenceCountUtil.release(writtenResponse);
assertFalse(channel.finishAndReleaseAll());
}
@Test
public void testConnectionCloseHeaderHandledCorrectlyForVoidPromise() throws Exception {
HttpResponse response = new DefaultFullHttpResponse(httpVersion, responseStatus);
response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE);
setupMessageLength(response);
channel.writeAndFlush(response, channel.voidPromise());
HttpResponse writtenResponse = channel.readOutbound();
assertFalse(channel.isOpen());
ReferenceCountUtil.release(writtenResponse);
assertFalse(channel.finishAndReleaseAll());
}
@Test
public void test_PipelineKeepAlive() {
FullHttpRequest firstRequest = new DefaultFullHttpRequest(httpVersion, HttpMethod.GET, "/v1/foo/bar");