Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix http input keep-alive handling
We were only responding to the first request on an http keep-alive connection
with a 202.
Any following requests would not be answered, leading to a timeout in the client.

Configuring a ChannelFuture for CLOSE_ON_FAILURE did expose the reason
for the bug:

`io.netty.handler.codec.EncoderException:
java.lang.IllegalStateException: unexpected message type:
DefaultHttpResponse, state: 1`

We ought to use `DefaultFullHttpResponse` instead of `DefaultHttpResponse`.
Also keep the `CLOSE_ON_FAILURE` to make this more robust for future bugs.

Fixes #5720
  • Loading branch information
mpfz0r committed Feb 27, 2019
1 parent bcf53ec commit 4488967
Showing 1 changed file with 4 additions and 6 deletions.
Expand Up @@ -22,7 +22,7 @@
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.DefaultHttpResponse;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
Expand Down Expand Up @@ -74,7 +74,7 @@ private void writeResponse(Channel channel,
HttpVersion httpRequestVersion,
HttpResponseStatus status,
String origin) {
final HttpResponse response = new DefaultHttpResponse(httpRequestVersion, status);
final HttpResponse response = new DefaultFullHttpResponse(httpRequestVersion, status);

response.headers().set(HttpHeaderNames.CONTENT_LENGTH, 0);
response.headers().set(HttpHeaderNames.CONNECTION, keepAlive ? HttpHeaderValues.KEEP_ALIVE : HttpHeaderValues.CLOSE);
Expand All @@ -87,8 +87,6 @@ private void writeResponse(Channel channel,

final ChannelFuture channelFuture = channel.writeAndFlush(response);

if (!keepAlive) {
channelFuture.addListener(ChannelFutureListener.CLOSE);
}
channelFuture.addListener(keepAlive ? ChannelFutureListener.CLOSE_ON_FAILURE : ChannelFutureListener.CLOSE);
}
}
}

0 comments on commit 4488967

Please sign in to comment.