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:
parent
464ae9fb7a
commit
174f4ea005
@ -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);
|
||||
}
|
||||
|
@ -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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user