From f053870f38b1f616328110a165075a6054d4a19f Mon Sep 17 00:00:00 2001 From: Arthur Gonigberg Date: Wed, 4 Nov 2020 05:01:08 -0800 Subject: [PATCH] Drop unknown frames on connection stream (#10771) Motivation: We received a [bug report](https://bugs.chromium.org/p/chromium/issues/detail?id=1143320) from the Chrome team at Google, their canary builds are failing [HTTP/2 GREASE](https://tools.ietf.org/html/draft-bishop-httpbis-grease-00) testing to netflix.com. The reason it's failing is that Netty can't handle unknown frames without an active stream created. Let me know if you'd like more info, such as stack traces or repro steps. Modification: The change is minor and simply ignores unknown frames on the connection stream, similarly to `onWindowUpdateRead`. Result: I figured I would just submit a PR rather than filing an issue, but let me know if you want me to do that for tracking purposes. --- .../netty/handler/codec/http2/Http2FrameCodec.java | 4 ++++ .../handler/codec/http2/Http2FrameCodecTest.java | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameCodec.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameCodec.java index f0ea63f159..390fde5a9b 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameCodec.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameCodec.java @@ -532,6 +532,10 @@ public class Http2FrameCodec extends Http2ConnectionHandler { @Override public void onUnknownFrame( ChannelHandlerContext ctx, byte frameType, int streamId, Http2Flags flags, ByteBuf payload) { + if (streamId == 0) { + // Ignore unknown frames on connection stream, for example: HTTP/2 GREASE testing + return; + } onHttp2Frame(ctx, new DefaultHttp2UnknownFrame(frameType, flags, payload) .stream(requireStream(streamId)).retain()); } diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2FrameCodecTest.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2FrameCodecTest.java index cf2ad106e6..1f433a003f 100644 --- a/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2FrameCodecTest.java +++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2FrameCodecTest.java @@ -389,6 +389,18 @@ public class Http2FrameCodecTest { assertEquals(0, frame.refCnt()); } + @Test + public void unknownFrameTypeOnConnectionStream() throws Exception { + // handle the case where unknown frames are sent before a stream is created, + // for example: HTTP/2 GREASE testing + ByteBuf debugData = bb("debug"); + frameInboundWriter.writeInboundFrame((byte) 0xb, 0, new Http2Flags(), debugData); + channel.flush(); + + assertEquals(0, debugData.refCnt()); + assertTrue(channel.isActive()); + } + @Test public void goAwayLastStreamIdOverflowed() throws Exception { frameInboundWriter.writeInboundHeaders(5, request, 31, false);