why http/2 stream id must be ascending?
Asked Answered
L

2

6

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!

Libby answered 10/3, 2017 at 13:48 Comment(0)
T
10

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.

Tushy answered 10/3, 2017 at 14:36 Comment(1)
That sounds reasonableLibby
A
4

6.8. GOAWAY

The GOAWAY frame (type=0x7) is used to initiate shutdown of a connection or to signal serious error conditions. GOAWAY allows an endpoint to gracefully stop accepting new streams while still finishing processing of previously established streams. This enables administrative actions, like server maintenance.

There is an inherent race condition between an endpoint starting new streams and the remote sending a GOAWAY frame. To deal with this case, the GOAWAY contains the stream identifier of the last peer- initiated stream that was or might be processed on the sending endpoint in this connection. For instance, if the server sends a GOAWAY frame, the identified stream is the highest-numbered stream initiated by the client.

Once sent, the sender will ignore frames sent on streams initiated by the receiver if the stream has an identifier higher than the included last stream identifier. Receivers of a GOAWAY frame MUST NOT open additional streams on the connection, although a new connection can be established for new streams.

If the receiver of the GOAWAY has sent data on streams with a higher stream identifier than what is indicated in the GOAWAY frame, those streams are not or will not be processed. The receiver of the GOAWAY frame can treat the streams as though they had never been created at all, thereby allowing those streams to be retried later on a new connection.

Arta answered 29/10, 2018 at 3:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.