Limit Redis inline command allocation by wwbmmm · Pull Request #3363 · apache/brpc · GitHub
Skip to content

Limit Redis inline command allocation#3363

Open
wwbmmm wants to merge 2 commits into
apache:masterfrom
wwbmmm:limit-redis-inline-command-allocation
Open

Limit Redis inline command allocation#3363
wwbmmm wants to merge 2 commits into
apache:masterfrom
wwbmmm:limit-redis-inline-command-allocation

Conversation

@wwbmmm

@wwbmmm wwbmmm commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: null

Problem Summary:

Redis inline command parsing copied the full input buffer before checking
whether a complete line had arrived. A long pending inline command could make
the parser repeatedly allocate and copy buffered data while waiting for CRLF.

What is changed and the side effects?

Changed:

  • Scan Redis inline commands for CRLF before allocating parser arena memory.
  • Apply redis_max_allocation_size to the current inline command line.
  • Copy only the current inline command line instead of the whole input buffer.
  • Add regression tests for an oversized inline command without a trailing CRLF
    and for pipelined inline input with a large incomplete next command.

Side effects:

  • Performance effects: Incomplete inline commands no longer allocate parser
    arena memory while waiting for CRLF, and complete inline commands only copy
    the current line.
  • Breaking backward compatibility: Inline Redis commands longer than
    redis_max_allocation_size are now rejected.

Check List:

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the Redis inline command parser to avoid repeated arena allocations/copies while waiting for \r\n, and enforces redis_max_allocation_size on inline command lines (rejecting oversized inline commands). It also adds regression coverage for oversized inline inputs and pipelined inline parsing.

Changes:

  • Scan for \r\n in inline commands before allocating from the parser arena, and only copy the current inline line once it is complete.
  • Enforce redis_max_allocation_size for inline command line length (reject over-limit inline commands).
  • Extend unit tests to cover oversized inline commands and pipelined inline input where the next command is incomplete/oversized.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/brpc/redis_command.cpp Adds pre-scan for CRLF and applies allocation size limits to inline command parsing to prevent repeated copying/allocations.
test/brpc_redis_unittest.cpp Adds regression tests for oversized inline commands and pipelined inline parsing behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/brpc/redis_command.cpp
Comment thread test/brpc_redis_unittest.cpp
@wwbmmm

wwbmmm commented Jun 28, 2026

Copy link
Copy Markdown
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants