Search code examples
http2

Why is the following sequence of events resulting in a protocol error?


I am playing around with an HTTP2 client/server implementation and I'm running into a protocol_error but I'm not sure why.

Received frame: {:length=>18, :type=>:settings, :flags=>[], :stream=>0, :payload=>[[:settings_max_concurrent_streams, 128], [:settings_initial_window_size, 65536], [:settings_max_frame_size, 16777215]]}
Sent frame: {:type=>:settings, :stream=>0, :payload=>[], :flags=>[:ack]}
Received frame: {:length=>4, :type=>:window_update, :flags=>[], :stream=>0, :increment=>2147418112}
Sent frame: {:type=>:headers, :flags=>[:end_headers, :end_stream], :payload=>{":scheme"=>"https", ":method"=>"GET", ":path"=>"/index", ":authority"=>"www.example.com"}, :stream=>1}
Received frame: {:length=>8, :type=>:goaway, :flags=>[], :stream=>0, :last_stream=>0, :error=>:protocol_error}

I'm almost certain this is a problem with stream IDs but I'm really new to the HTTP2 protocol so I'm actually not sure what's going wrong or why I'm getting the protocol error.


Solution

  • I would guess it is because you have not sent your Settings Frame - you have only acknowledged the server Settings Frame.

    The spec could be clearer on this:

    A SETTINGS frame MUST be sent by both endpoints at the start of a connection

    Does an acknowledgement Settings Frame count?

    However this section states:

    This sequence MUST be followed by a SETTINGS frame (Section 6.5), which MAY be empty. ... The SETTINGS frames received from a peer as part of the connection preface MUST be acknowledged (see Section 6.5.3) after sending the connection preface.

    So I’m taking that as you must send your Settings Frame and then acknowledge the server Settings Frame.