Skip to content

Simplify HPACK parser#26787

Closed
ctiller wants to merge 42 commits intogrpc:masterfrom
ctiller:hpack-2
Closed

Simplify HPACK parser#26787
ctiller wants to merge 42 commits intogrpc:masterfrom
ctiller:hpack-2

Conversation

@ctiller
Copy link
Copy Markdown
Member

@ctiller ctiller commented Jul 26, 2021

This PR leverages the work done in #26700 to eliminate all parsing state stored on HPackParser, and the need for a state machine driven parser at all.

ctiller and others added 21 commits July 15, 2021 14:57
HTTP2 headers are sent in (potentially) many frames, but all must be
sent sequentially with no traffic intervening.

This was not clear when I wrote the HPACK parser, and still indeed quite
contentious on the HTTP2 mailing lists.

Now that matter is well settled (years ago!) take advantage of the fact
by delaying parsing until all bytes are available.

A future change will leverage this to avoid having to store and verify
partial parse state, completely eliminating indirect calls within the
parser.
This reverts commit 258d712.
@ctiller ctiller added disposition/Work In Progress release notes: no Indicates if PR should not be in release notes labels Jul 26, 2021
@ctiller ctiller requested review from arjunroy and yashykt July 26, 2021 15:52
@ctiller
Copy link
Copy Markdown
Member Author

ctiller commented Jul 29, 2021 via email

@ejona86
Copy link
Copy Markdown
Member

ejona86 commented Jul 29, 2021

even try to restart mid
header - it was adding a lot here, and we don't need it.

Well, MAX_HEADER_LIST_SIZE is advisory and the only option for dealing with overbuffering without stream-parsing headers is killing the connection, which combined together can produce very bad results.

From what I've seen, it doesn't require much state to restart on header boundary. The main thing it requires is the various parts of the parsing to be able to fail due to too little buffer and ifs to propagate that out through the layers.

@ctiller
Copy link
Copy Markdown
Member Author

ctiller commented Jul 29, 2021 via email

@ctiller
Copy link
Copy Markdown
Member Author

ctiller commented Jul 29, 2021 via email

@ejona86
Copy link
Copy Markdown
Member

ejona86 commented Jul 29, 2021

So for compatibility with C core clients should consider MAX_HEADER_LIST_SIZE mandatory. I understand you are allowed to kill the connection when things become excessive, but that seems draconian.

@ejona86
Copy link
Copy Markdown
Member

ejona86 commented Jul 29, 2021

One middle-ground solution is to let, say, 2x MAX_HEADER_LIST_SIZE buffering HEADERS and respond with a clean error. If the 2x limit is reached then kill the connection. But when MAX_HEADER_LIST_SIZE is 8 KB, 2x doesn't go very far.

@ctiller
Copy link
Copy Markdown
Member Author

ctiller commented Jul 29, 2021 via email

@ctiller
Copy link
Copy Markdown
Member Author

ctiller commented Jul 29, 2021 via email

@ctiller
Copy link
Copy Markdown
Member Author

ctiller commented Jul 29, 2021

This is now a streaming parser.

@ctiller
Copy link
Copy Markdown
Member Author

ctiller commented Jul 29, 2021

And I'd claim ready for review for real this time.

@ejona86
Copy link
Copy Markdown
Member

ejona86 commented Jul 30, 2021

Nicely readable.

Something to be wary of: a very long header entry. E.g., let's say a header value is MAX_INT in length. If an entry is greater than MAX_HEADER_LIST_SIZE and greater than the HPACK table size, then it can be skipped (and the HPACK table would be cleared).

@ctiller ctiller mentioned this pull request Jul 31, 2021
@ctiller
Copy link
Copy Markdown
Member Author

ctiller commented Aug 4, 2021

@yashykt ping on this review

@ctiller
Copy link
Copy Markdown
Member Author

ctiller commented Aug 9, 2021

Ping?

Copy link
Copy Markdown
Member

@yashykt yashykt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

net effect: -347 LOC! Love it!

Copy link
Copy Markdown
Member

@yashykt yashykt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arjunroy please take a look too

@ctiller
Copy link
Copy Markdown
Member Author

ctiller commented Aug 9, 2021

Merged with #26851

@ctiller ctiller closed this Aug 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release notes: no Indicates if PR should not be in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants