fix(error): detect READONLY errors from Lua scripts on read-only replicas#3769
Merged
ndyakov merged 1 commit intoApr 9, 2026
Merged
Conversation
|
Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset. In case there are security findings, they will be communicated to you as a comment inside the PR. Hope you’ll enjoy using Jit. Questions? Comments? Want to learn more? Get in touch with us. |
d2e8a89 to
13241c0
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 13241c0. Configure here.
…icas When a Lua script containing a write command is executed against a read-only replica in a Redis Cluster, the error may contain "-READONLY You can't write against a read only replica" embedded within a larger error message rather than starting with "READONLY ". The existing code only checked for the "READONLY " prefix, missing this format. This caused shouldRetry() and isReadOnlyError() to fail, preventing automatic retry and connection pool cleanup. The fix checks for the exact substring "-READONLY You can't write against a read only replica" which is specific enough to avoid false positives while catching the Lua script error format. Closes redis#2770 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
13241c0 to
9a2a9e3
Compare
ndyakov
approved these changes
Apr 9, 2026
ndyakov
left a comment
Member
There was a problem hiding this comment.
this looks good @zhengjilei, thank you!
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.

Summary
READONLYerrors embedded in Lua script error messages on read-only replicas"-READONLY You can't write against a read only replica"to avoid false positivesSupersedes #2770 — incorporates reviewer feedback from @ndyakov (stricter matching) and @ofekshenawa (unit tests).
Problem
When a Lua script containing a write command executes against a read-only replica in a Redis Cluster, the error may contain
-READONLY You can't write against a read only replicaembedded within a larger error message rather than starting withREADONLY:The existing code only checks
strings.HasPrefix(s, "READONLY "), missing this embedded format. This causes:shouldRetry()to not retry the commandisReadOnlyError()to not detect it, preventing connection pool cleanup viaisBadConn()LazyReload()to not trigger cluster state refreshChanges
internal/proto/redis_errors.goIsReadOnlyError()to check for"-READONLY You can't write against a read only replica"substringerror.goshouldRetry()internal/proto/redis_errors_test.goTestIsReadOnlyErrorWithLuaScriptErrorswith 7 test caseserror_wrapping_test.goTestLuaScriptReadOnlyErrorwith 5 test cases + retry testerror_test.goshouldRetryginkgo testAddressing PR #2770 Reviewer Feedback
@ndyakov's concern: The original PR used
strings.Contains(s, "-READONLY")which is too broad — could match keys like"something-READONLY".This fix: Checks for the exact substring
"-READONLY You can't write against a read only replica"— specific enough to only match actual READONLY errors without any false positives.Integration Test Report (Redis 7.2.7 Cluster)
Tested against a local 6-node Redis Cluster (3 masters + 3 replicas):
Test plan
IsReadOnlyErrorwith Lua script error format (proto package)ShouldRetrywith Lua script READONLY errorgo test ./internal/proto/andgo test -run Test)🤖 Generated with Claude Code