This repository was archived by the owner on Oct 25, 2026. It is now read-only.
Repository navigation
Conversation
LIMIT may be given more than once, and the parser keeps only the last value. The propagation rewrite added in #4063 recorded only the last LIMIT position, so XADD s MAXLEN ~ 10 LIMIT 5 LIMIT 6 * f v propagated as MAXLEN = <len> LIMIT 5. A client that is not mustObeyClient, such as a migration tool replaying the stream, gets "LIMIT cannot be used without the special ~ option" for it. Record the first LIMIT position and drop every LIMIT pair between it and the end of the options. Signed-off-by: Madelyn Olson <madelyneolson@gmail.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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
XADD and XTRIM accept LIMIT more than once and keep the last value, but the propagation rewrite from #4063 strips only the last LIMIT.
XADD s MAXLEN ~ 55 LIMIT 5 LIMIT 30 * f vpropagates asMAXLEN = 71 LIMIT 5, which a client that is notmustObeyClient, such as a migration tool replaying the stream, rejects. This records the first LIMIT position and drops every LIMIT pair in the options. Replicas and AOF loading are unaffected because they ignore LIMIT.AI generated details
Problem
streamParseAddOrTrimArgsOrReplyoverwrotelimit_arg_idxon every LIMIT (src/t_stream.c:975), sostreamRewriteStripLimitremoved only the last pair. Whatever LIMIT is left ends up next to the rewrittenMAXLEN =/MINID =, and a non-obeyed replay fails:Introduced by #4063 (c03970a), first in 9.2.0-rc1. The repeated-LIMIT parsing goes back to #8169. Before #4063, every explicit LIMIT was propagated.
XADD s MAXLEN ~ 55 LIMIT 5 LIMIT 30 * f vMAXLEN = 71 LIMIT 5MAXLEN = 71XADD s LIMIT 5 MAXLEN ~ 55 LIMIT 30 * f vLIMIT 5 MAXLEN = 71MAXLEN = 71XTRIM s MAXLEN ~ 50 LIMIT 5 LIMIT 30MAXLEN = 70 LIMIT 5MAXLEN = 70The existing test from #4063 passes a single LIMIT, so it never hit this.
Fix
The parser records the first LIMIT (
src/t_stream.c:977).streamRewriteStripAllLimits(src/t_stream.c:2099) scans from there to the end of the options (idposfor XADD,argcfor XTRIM) and calls the existingstreamRewriteStripLimiton eachLIMITtoken. Matching by string is safe because every option value has already parsed as an integer, a stream ID,~or=, and none of those can belimit. The key and the fields are outside the scanned range. The rewritten trim argument can be integer encoded, hence thesdsEncodedObject()check.Alternative considered
Rejecting repeated LIMIT at parse time, as repeated MAXLEN already is. That makes a command that has been accepted since LIMIT was introduced fail, which is a compatibility change and not a fix to the rewrite.
Testing
New test in
tests/unit/type/stream.tclthat covers LIMIT before and after the trim strategy, with NOMKSTREAM, for XADD and XTRIM. Withsrc/t_stream.creverted:This was generated by AI but verified, with love, by a human.