Repository navigation
Drain RESP3 attributes so they never reach the kept reply - #882
Conversation
An attribute frame (|N) was parsed as an ordinary aggregate: its pairs were materialized as the root of the kept mbulk tree, counted as hits and as tracked elements, and a nested attribute took a slot of the enclosing aggregate. With keep_value the following reply then wrote through a NULL cursor (|0 *1 +a, or an attribute on an array element), and an attribute inside an attribute hit the !m_attribute assert. Without keep_value an attribute on an array element was recorded as two extra elements for ArrayPerElementNulls, and attribute bulks were counted as hits. An attribute only decorates the element after it, so drain it in its own scope with the existing nested-push machinery: it takes no slot of its parent, writes nothing into the reply, and anything inside it (another attribute or a push) is drained with it. When it ends the parser resumes as if it had not been there; at top level the reply goes on. Fixes #458. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this. I checked the new
The tests exercise the three crash shapes plus the EmptyCollection and ArrayPerElementNulls counting cases, and they fail on master. That's the right bar for a parser fix like this. The visible change for users is that Hits/Misses (and the per-element miss tracking) no longer count attribute contents when the server sends attributes. That fixes the miscount reported in #458; it doesn't break compatibility, but it may be worth a line in the release notes. You already flagged the #832 comment that says a nested attribute "takes a parent slot". Whichever of the two PRs merges second should fix that comment, so the stale wording doesn't end up in master. Nitpicking: The core fix looks solid to me. Since this is core RESP3 framing, it may still be worth a second look from whoever owns the protocol parser before merge. |
…in attributes An attribute is always drained in a nested scope now, which the nested branch of response_ended() ends; m_attribute is never set past it, so the was_attribute handling and its comment no longer describe anything. Add cases for an error inside an attribute (not the reply's error) and after it (the reply's error). Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Confirmed, and removed in 58633aa. With this change 58633aa removes the The same commit adds unit cases for an error inside an attribute ( |
An attribute is drained in its own nested scope and only when no push is being drained, so a push nested in an aggregate never starts while an attribute is open: the saved flag was always false. Restore false directly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Right, it's dead. Removed in 142b915. An attribute only opens its drain scope when |
An attribute sets m_push before the top-array-length and miss-tracking blocks run, so their line[0] != '|' conditions never changed anything. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Right, they were redundant. Removed in 04b2236. An attribute sets |
An attribute inside a push takes none of the push's slots: a nested push holding one fills one slot of its aggregate, and a top-level push holding one is drained whole before the reply. Master ends such a push early and hands its last element back as the reply; both cases fail there. In the nested-push branch m_attribute is already false (an attribute sets m_push), so stop clearing it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Both done in 15cb853. The new cases are |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Done in a173343, a comment-only change. |
#832's bound comment and unit-test comment said a nested attribute takes a parent slot; with this PR an attribute is drained in its own scope and takes none. Keep #832's bound and say so. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fixes #458.
redis_protocol::parse_response()treated a RESP3 attribute (|N) like an ordinary aggregate. Its key/value pairs became part of the reply. Withset_keep_value(true)that crashes. The three forms in the issue comments all reproduce on master under ASan + UBSan:|0\r\n*1\r\n+a\r\n: the attribute becomes the root of the kept tree, and the next aggregate callsadd_new_element()on a NULL cursor (protocol.cpp:764).assert(!m_attribute).*2\r\n|1\r\n+k\r\n+v\r\n+a\r\n*1\r\n+b\r\n: it takes one of the parent's slots, so the reply ends early, and the following aggregate dereferences NULL.Without keep_value, the attribute's elements were counted as hits and as ArrayPerElementNulls elements, which is the miscount the issue describes. An error inside an attribute also marked the whole reply as an error; it no longer does.
Fix (
protocol.cpponly). An attribute is now drained in its own scope, the same way a nested push (>) already is. It takes no slot from its parent, and anything inside it (another attribute, or a push) is drained with it. When it ends, parsing continues as if it weren't there; at top level, the reply goes on. Nothing from an attribute is ever added to the reply tree, so there is nothing to free.Tests. A new
check_attribute_frames()intests/unit/redis_protocol_test.cppcovers:*0(still empty for EmptyCollection, with and without keep_value)Against master's
protocol.cpp, each crash form aborts under ASan (null member call, or the assertion) and the counting cases give wrong results. With the fix every case passes.Results (Ubuntu 24.04 container, ASan + UBSan):
make checkpasses, and clang-format is clean.test_resp_response_fuzzer.py,test_read_preference_resp3.py,test_arbitrary_command_misses.pyandtest_collection_scan.pypass 47/47.#832 (also in
protocol.cpp/redis_protocol_test.cpp) merges cleanly with this, and the merged tree's sanitized unit test passes, including #832's nested-attribute bound checks. Once both land, a comment in #832 saying a nested attribute "takes a parent slot" will be out of date.Release notes (proposed)
🤖 Generated with Claude Code
Note
Medium Risk
Changes core RESP3 reply parsing and completion logic; incorrect draining could mis-frame replies or miscount benchmark metrics, but behavior is heavily covered by new unit tests.
Overview
Fixes #458 by treating RESP3 attribute frames (
|) as drain-only metadata, like nested push (>), instead of ordinary aggregates.redis_protocol::parse_response()enters push/drain mode when an attribute is seen: it does not consume a parent slot, does not build the kept mbulk tree, and does not affect hits, per-element miss tracking, top-level array length, or reply error state. Nested attributes and pushes inside an attribute are drained with it.response_ended()was updated so finishing an attribute continues parsing the real reply;m_push_outer_attributewas removed as redundant.Tests: new
check_attribute_frames()covers crash cases, keep_value tree shape, EmptyCollection, ArrayPerElementNulls, and updated overflow-bound comments for attributes taking no parent slot.Reviewed by Cursor Bugbot for commit c22e077. Bugbot is set up for automated code reviews on this repo. Configure here.