Repository navigation
Fix protocol error not reported when a command is split across reads - #15795
Merged
sundb merged 3 commits intoSep 24, 2026
Merged
Conversation
sundb
reviewed
Sep 23, 2026
A command that is parsed across several reads keeps its pendingCommand alive between calls, with PENDING_CMD_FLAG_INCOMPLETE set. When a protocol error is found on one of the later reads, processMultibulkBuffer() records it in pcmd->read_error and returns early, before the tail of the function that clears the flag. addPendingCommand() only counts a command as ready when that flag is clear, so ready_len stays zero and processInputBuffer() breaks out of the loop before copying read_error to the client. The error is recorded and then dropped: the client never gets a reply, and its query buffer keeps growing until it reaches client-query-buffer-limit. The same bytes are reported correctly when they arrive in a single read, because the command is then still freshly acquired and not yet flagged as incomplete. This affects every error raised inside the multibulk argument loop: too big bulk count string, expected '$', invalid bulk length and unauthenticated bulk length. Of these, too big bulk count string was unreachable in practice, because a bulk count string above the 64k limit always spans more than one read. Route those four error exits through a single err label that clears the flag on the way out, so the command is queued as ready and the error reaches the client. The three errors raised while multibulklen is still zero do not need it: the command is freshly acquired there and the flag is never set. Tests are added for the two split-read cases and for the three size limits, none of which were covered before.
pirate329
force-pushed
the
fix-protocol-error-after-partial-read
branch
from
September 23, 2026 06:56
7068517 to
40c2a3d
Compare
sundb
reviewed
Sep 23, 2026
sundb
reviewed
Sep 23, 2026
The three errors raised while multibulklen is still zero could not hit the bug on their own, since the pending command is always freshly acquired there and the flag is never set. Going through err keeps all the read_error exits consistent and means a new error added there cannot reintroduce it. The two returns that only mean "not enough data yet" are left as they are, since they are not errors.
sundb
reviewed
Sep 23, 2026
The label only handles read errors, and readerr matches the existing one in aof.c as well as the other qualified error labels in the tree.
Contributor
Author
|
@sundb could you approve the workflow run when you get a chance? CI went green on the previous commit and the label rename is the only change since. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## unstable #15795 +/- ##
============================================
+ Coverage 76.94% 77.60% +0.66%
============================================
Files 145 146 +1
Lines 87695 87999 +304
============================================
+ Hits 67477 68294 +817
+ Misses 20218 19705 -513
🚀 New features to boost your workflow:
|
sundb
approved these changes
Sep 24, 2026
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.
A command that is parsed across several reads keeps its pendingCommand alive between calls, with PENDING_CMD_FLAG_INCOMPLETE set. When a protocol error is found on one of the later reads, processMultibulkBuffer() records it in pcmd->read_error and returns early, before the tail of the function that clears the flag. addPendingCommand() only counts a command as ready when that flag is clear, so ready_len stays zero and processInputBuffer() breaks out of the loop before copying read_error to the client. The error is recorded and then dropped: the client never gets a reply, and its query buffer keeps growing until it reaches client-query-buffer-limit.
The same bytes are reported correctly when they arrive in a single read, because the command is then still freshly acquired and not yet flagged as incomplete.
This affects every error raised inside the multibulk argument loop: too big bulk count string, expected '$', invalid bulk length and unauthenticated bulk length. Of these, too big bulk count string was unreachable in practice, because a bulk count string above the 64k limit always spans more than one read.
Clear the flag when a read error is set, so that the command is queued as ready and the error reaches the client.
Tests are added for the two split-read cases and for the three size limits, none of which were covered before.
Runnable reproduction
Save as
repro.pyand run it against a server withpython3 repro.py [port].The
time.sleep()between the two writes is the essential part: it forces the server into a separateread(). Without it both halves usually arrive in a single read and the error is reported correctly, which hides the problem.Before this patch:
After:
The hanging connections stay open and keep buffering. On an unpatched build they are only closed once they reach
client-query-buffer-limit, which defaults to 1GB.Note
Medium Risk
Changes core client input parsing in networking.c; behavior is narrower (fail fast with an error reply) but affects every multibulk parse error path.
Overview
Fixes a bug where RESP multibulk protocol errors detected on a later read were stored on the pending command but never sent to the client, leaving connections hanging and the query buffer growing until
client-query-buffer-limit.In
processMultibulkBuffer(), error paths that setpcmd->read_errornow jump to a sharedreaderrlabel instead of returning immediately. That path clearsPENDING_CMD_FLAG_INCOMPLETEso the command is treated as ready andprocessInputBuffer()can surface the error—matching behavior when the bad bytes arrive in one read.tests/unit/protocol.tcladds coverage for split-write protocol failures (wrong bulk prefix, invalid bulk length) and for oversized inline/multibulk/bulk count strings that previously could not be exercised when the header spanned reads.Reviewed by Cursor Bugbot for commit 35cd707. Bugbot is set up for automated code reviews on this repo. Configure here.