Fix inline redis protocol consuming HTTP/2 connection preface (#3109)#3338
Open
rajvarun77 wants to merge 1 commit into
Open
Fix inline redis protocol consuming HTTP/2 connection preface (#3109)#3338rajvarun77 wants to merge 1 commit into
rajvarun77 wants to merge 1 commit into
Conversation
…#3109) Inline redis protocol support (apache#3024) accepts any alpha-leading line as an inline command. The HTTP/2 client connection preface ("PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n") is alpha-leading, so it was parsed as an inline command instead of returning PARSE_ERROR_TRY_OTHERS. This prevented protocol auto-detection from falling through to HTTP/2, and gRPC clients calling a server with redis_service enabled failed with "connection closed before server preface received". Detect the HTTP/2 preface (fully, or as a not-yet-complete prefix) in the inline branch of RedisCommandParser::ConsumeImpl and defer to other protocols. A command-name blacklist is not viable because some HTTP methods are also valid redis commands (e.g. GET), whereas the preface is a fixed magic string that no redis command begins with, making the check unambiguous. Add RedisTest.inline_does_not_eat_h2_preface covering the full preface, a partial prefix, and a genuine inline command sharing the leading byte. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem does this PR solve?
Issue Number: #3109
Problem Summary:
Inline redis protocol support (#3024) accepts any alpha-leading line as an inline command. The HTTP/2 client connection preface (
PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n) is alpha-leading, soRedisCommandParser::ConsumeImplparsed it as an inline command (first tokenPRI) and returnedPARSE_OKinstead ofPARSE_ERROR_TRY_OTHERS.As a result, protocol auto-detection in
InputMessengernever fell through to the HTTP/2 handler, and a gRPC client calling a brpc server withredis_serviceenabled failed with:What is changed and the side effects?
Changed:
RedisCommandParser::ConsumeImpl(src/brpc/redis_command.cpp), detect the HTTP/2 connection preface — both a full match and a not-yet-complete prefix — and returnPARSE_ERROR_TRY_OTHERS, leaving the buffer untouched so detection falls through to the HTTP/2 protocol.'P') to avoid overhead on normal inline commands.Why match the preface rather than blacklist command names: some HTTP methods are also valid redis commands (e.g.
GET), so a name-based blacklist is inherently ambiguous. The HTTP/2 preface is a fixed magic string that no redis command begins with, so matching it is unambiguous and has no false positives (no redis command starts withPR…).RedisTest.inline_does_not_eat_h2_preface(test/brpc_redis_unittest.cpp) covering: the full preface →TRY_OTHERS; a partial prefix →TRY_OTHERS; and a genuine inline command sharing the leading byte (PING) →PARSE_OK.Side effects:
memcmponly when it is'P'.