From cea577f43ce3dd743ad0612bb2eacb1e75dae540 Mon Sep 17 00:00:00 2001 From: Doug Fawley Date: Wed, 11 Sep 2019 10:34:34 -0700 Subject: [PATCH] server: set and advertise max frame size of 16KB (#3018) --- internal/transport/http2_server.go | 5 ++++- internal/transport/http_util.go | 1 + test/channelz_test.go | 6 +++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/transport/http2_server.go b/internal/transport/http2_server.go index 44b49ab06c9a..08e3f852ed07 100644 --- a/internal/transport/http2_server.go +++ b/internal/transport/http2_server.go @@ -132,7 +132,10 @@ func newHTTP2Server(conn net.Conn, config *ServerConfig) (_ ServerTransport, err } framer := newFramer(conn, writeBufSize, readBufSize, maxHeaderListSize) // Send initial settings as connection preface to client. - var isettings []http2.Setting + isettings := []http2.Setting{{ + ID: http2.SettingMaxFrameSize, + Val: http2MaxFrameLen, + }} // TODO(zhaoq): Have a better way to signal "no limit" because 0 is // permitted in the HTTP2 spec. maxStreams := config.MaxStreams diff --git a/internal/transport/http_util.go b/internal/transport/http_util.go index 9d212867ce2e..8f5f3349d906 100644 --- a/internal/transport/http_util.go +++ b/internal/transport/http_util.go @@ -667,6 +667,7 @@ func newFramer(conn net.Conn, writeBufferSize, readBufferSize int, maxHeaderList writer: w, fr: http2.NewFramer(w, r), } + f.fr.SetMaxReadFrameSize(http2MaxFrameLen) // Opt-in to Frame reuse API on framer to reduce garbage. // Frames aren't safe to read from after a subsequent call to ReadFrame. f.fr.SetReuseFrames() diff --git a/test/channelz_test.go b/test/channelz_test.go index 0adf0e886317..d774002646dc 100644 --- a/test/channelz_test.go +++ b/test/channelz_test.go @@ -864,7 +864,11 @@ func doServerSideInitiatedFailedStreamWithClientBreakFlowControl(tc testpb.TestS } // sleep here to make sure header frame being sent before the data frame we write directly below. time.Sleep(10 * time.Millisecond) - payload := make([]byte, 65537) + payload := make([]byte, 16384) + dw.getRawConnWrapper().writeRawFrame(http2.FrameData, 0, tc.(*testServiceClientWrapper).getCurrentStreamID(), payload) + dw.getRawConnWrapper().writeRawFrame(http2.FrameData, 0, tc.(*testServiceClientWrapper).getCurrentStreamID(), payload) + dw.getRawConnWrapper().writeRawFrame(http2.FrameData, 0, tc.(*testServiceClientWrapper).getCurrentStreamID(), payload) + dw.getRawConnWrapper().writeRawFrame(http2.FrameData, 0, tc.(*testServiceClientWrapper).getCurrentStreamID(), payload) dw.getRawConnWrapper().writeRawFrame(http2.FrameData, 0, tc.(*testServiceClientWrapper).getCurrentStreamID(), payload) if _, err := stream.Recv(); err == nil || status.Code(err) != codes.ResourceExhausted { t.Fatalf("%v.Recv() = %v, want error code: %v", stream, err, codes.ResourceExhausted)