Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 241
Paul Yang Avatar asked Mar 10 '17 13:03

Paul Yang


2 Answers

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.

like image 168
sbordet Avatar answered Sep 27 '22 21:09

sbordet


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.

like image 22
Chen Jiling Avatar answered Sep 27 '22 21:09

Chen Jiling