Search code examples
http2rfcmultiplexing

why http/2 stream id must be ascending?


in RFC 7540 section 5.1.1. (https://www.rfc-editor.org/rfc/rfc7540#section-5.1.1), it specifies as following:

The identifier of a newly established stream MUST be numerically greater than all streams that the initiating endpoint has opened or reserved.

I searched a lot on Google, but still no one explained why the stream ID must be in an ascending order. I don't see any benefit from making this rule to the protocol. From my point of view, out of order stream IDs should also work well if the server just consider the "stream ID" as an ID and use it to distinguish HTTP2 request.

So could anyone can help out explaining the exact reason for this specification?

Thanks a lot!


Solution

  • Strictly ascending stream IDs are an easy way to make them unique (per connection), and it's super-easy to implement.

    Choosing - like you say - "out of order" stream IDs is potentially more complicated, as it requires to avoid clashes, and potentially consumes more resources, as you have to remember all the stream IDs that are in use.

    I don't think there is any particular reason to specify that stream IDs must be ascending apart simplicity.