netty: work around netty bug when RPCs may be reset early

For netty/netty#6296
This commit is contained in:
Carl Mastrangelo 2017-01-30 16:09:19 -08:00 committed by GitHub
parent 237a65ebfc
commit fdeade4ee2
1 changed files with 11 additions and 3 deletions

View File

@ -352,10 +352,18 @@ class NettyServerHandler extends AbstractNettyHandler {
*/
private void sendResponseHeaders(ChannelHandlerContext ctx, SendResponseHeadersCommand cmd,
ChannelPromise promise) throws Http2Exception {
if (cmd.endOfStream()) {
closeStreamWhenDone(promise, cmd.stream().id());
// TODO(carl-mastrangelo): remove this check once https://github.com/netty/netty/issues/6296 is
// fixed.
int streamId = cmd.stream().id();
Http2Stream stream = connection().stream(streamId);
if (stream == null) {
resetStream(ctx, streamId, Http2Error.CANCEL.code(), promise);
return;
}
encoder().writeHeaders(ctx, cmd.stream().id(), cmd.headers(), 0, cmd.endOfStream(), promise);
if (cmd.endOfStream()) {
closeStreamWhenDone(promise, streamId);
}
encoder().writeHeaders(ctx, streamId, cmd.headers(), 0, cmd.endOfStream(), promise);
}
private void cancelStream(ChannelHandlerContext ctx, CancelServerStreamCommand cmd,