Repository navigation
v4 Scripts: build the NOSCRIPT retry from the rendered EVALSHA, not the caller's spans - #3398
Merged
Merged
Conversation
…caller's spans The repair captured keys/args with ToArray() whenever the send had not completed synchronously. That copied the RedisValues but not the memory under them, so a caller who returned a pooled buffer after the call returned had the retry send whatever was there by the time NOSCRIPT arrived; and it cost two arrays on almost every real call. The retry now holds a reference to the rendered EVALSHA (a reference count, no copy) and re-renders EVAL from its arguments through the command map, without re-applying the key prefix the keys already carry.
…not defaulted Internal, so correctness wins over convenience: a caller that forgets to pass its token should not compile.
This was referenced Dec 3, 2026
v4: Redis 8.12 test topology (cluster bus protected mode, ZSCAN duplicates), from main's #3343
#3399
Merged
pairbit
added a commit
to pairbit/IT.Redis
that referenced
this pull request
Dec 3, 2026
* v4 design: generated scripts and functions (seredis#3401) * design: generated scripts and functions (exploratory) A shape for declaring server-side code as partial methods: binding by name, shared call shape, per-kind provisioning; facts checked against Redis 8.12. * design: functions are opaque names; administration on IServer, not in the pipeline * design: lists of keys and arguments, and how a script sees them * design: the general case - declared commands, after the marc/respite RespCommandGenerator * design: keyword clauses (prefix, suffix, count, ignore-when) as the core of the declared-command model * v4: Redis 8.12 test topology (cluster bus protected mode, ZSCAN duplicates), from main's seredis#3343 (seredis#3399) * CI (Windows): let Redis 8.12 start the cluster nodes 8.12 refuses a cluster node with an unauthenticated bus port unless cluster-bus-port-protected-mode is off; older servers reject the option, so it is passed only to 8.12 and later. * Redis 8.12 test topology, ported from main's seredis#3343: cluster-bus-port-protected-mode in the cluster confs, client-libs-test:8.12.0, and ZSCAN may return duplicates Replaces the version-gated CI.yml option: main already solves this in the cluster confs, and v4 follows it. * v4 Scripts: build the NOSCRIPT retry from the rendered EVALSHA, not the caller's spans (seredis#3398) * Scripts: build the NOSCRIPT retry from the rendered EVALSHA, not the caller's spans The repair captured keys/args with ToArray() whenever the send had not completed synchronously. That copied the RedisValues but not the memory under them, so a caller who returned a pooled buffer after the call returned had the retry send whatever was there by the time NOSCRIPT arrived; and it cost two arrays on almost every real call. The retry now holds a reference to the rendered EVALSHA (a reference count, no copy) and re-renders EVAL from its arguments through the command map, without re-applying the key prefix the keys already carry. * SendWithPreambleAsync: the gate and cancellation token are required, not defaulted Internal, so correctness wins over convenience: a caller that forgets to pass its token should not compile. --------- Co-authored-by: Marc Gravell <marc.gravell@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 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.
Fixes the two
Scripts.Evaluateissues raised in #3364 that don't need any new API.Problem
When the
SCRIPT LOAD+EVALSHApair hadn't completed synchronously,Repairablecapturedkeys.ToArray()/args.ToArray()in case it had to re-send behindEVALafter aNOSCRIPT. That caused two problems:RedisValueoverMemory<byte>still points at the caller's buffer. The arguments are only borrowed for the duration of the call, so a caller may hand a pooled buffer back as soon asEvaluateAsyncreturns. If the server then repliedNOSCRIPT(aSCRIPT FLUSH, a restart, a failover to a node that never saw the load), the retry sent whatever was in that buffer by then. No error is raised; the script just runs with the wrong arguments.Change
SendWithPreambleAsyncgains overloads (internal) that also hand back a reference of the caller's own to the detached request: a reference count, not a copy.Repairableholds that reference instead of the spans. It releases it immediately on the synchronous-success fast path, and otherwise once the reply is in.On
NOSCRIPT, the newRenderEvalreads the key count, keys and arguments back out of the renderedEVALSHAframe and rendersEVAL/EVAL_ROthe normal way:EVALis handled like any other command;WithoutKeyPrefix(), because the keys in the frame already carry the prefix;The copying happens only on the
NOSCRIPTpath.Tests
RespScriptRetryArgumentsTests(new). The fake raises an error reply asRedisServerException, as the real executor does, and can hold theEVALSHAreply until the caller has moved on.NOSCRIPTarrives, and the retry still sends the original bytes. Covered forEVALandEVAL_RO. On the currentv4code this test sends the overwritten bytes ($7|XXXXXXX|).NOSCRIPTis still repaired.$, digits, empty), and the zero-key case.EVALrenamed in the command map, and withEVALSHArenamed to a name of a different length.The new tests plus the existing script, preamble,
NOSCRIPT, end-to-end andSanityChecksclasses pass locally on net10.0 and net481, against the docker topology.