Repository navigation
fix(client): do not record a database whose SELECT failed inside MULTI - #3489
Merged
nkaradzhov merged 1 commit intoOct 7, 2026
Merged
Conversation
_executeMulti recorded the database from multi().select() for any non-null EXEC reply. Redis checks the SELECT index when EXEC runs, so multi().select(99).exec() gets an error in the SELECT slot while the connection stays on its database, yet the client recorded 99. The next reconnect sent SELECT 99 in the handshake, failed, and kept retrying, so the client never became ready again. Each SELECT in the transaction is now recorded from its own slot in the EXEC reply and skipped when that slot is an error, as _executePipeline already does for a pipeline. select(1).select(99) keeps db 1, and a raw SELECT added with addCommand() is recorded the same way.
nkaradzhov
approved these changes
Oct 7, 2026
nkaradzhov
left a comment
Collaborator
There was a problem hiding this comment.
Thanks! Matches the #3484 pipeline fix, and the new tests fail on master and pass here. LGTM.
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.
Description
client.multi().select(99).set('k', 'v').exec()rejects with MultiErrorReply, but the client still records 99 as its database. Redis checks the SELECT index when EXEC runs, so the connection stays on db 0 and the error sits in the SELECT slot of the EXEC reply, while_executeMultirecords the database for any non-null EXEC reply. After the next disconnect the handshake sendsSELECT 99, fails and retries, and the client never becomes ready again.Repro against a local Redis 8.10.2, killing the connection with
CLIENT KILLfrom a second client and waiting 4 s. On master:With this change the client reconnects and is ready.
Each SELECT in the transaction is now recorded from its own slot in the EXEC reply and skipped on an ErrorReply, same as
_executePipeline(#3484). That also keeps db 1 forselect(1).select(99)and records a rawselectadded withaddCommand().Added two tests in
index.spec.tsfor those two cases, both fail on master. Thepackages/clienttests pass; one sentinel lifecycle test failed once on master and passed here.Checklist
npm testpass with this change (including linting)?Note
Medium Risk
Changes reconnect handshake database selection after MULTI/EXEC; incorrect tracking could strand clients, but scope is limited to transaction SELECT handling with added regression tests.
Overview
Fixes a reconnect bug where the client could persist an invalid database index after a failed
SELECTinsideMULTI._executeMultino longer applies the multi builder’s queuedselectedDBafter a successfulEXEC. It walks each command in the transaction and updates#selectedDBonly when the command isSELECTand that command’s slot in theEXECreply is not anErrorReply—matching_executePipeline(#3484). Failed out-of-rangeSELECTs are ignored; successful earlierSELECTs in the same transaction still apply. Raw lowercaseselectviaaddCommandis recognized via case-insensitive command matching.Two integration tests in
index.spec.tscover failed vs successfulSELECTinMULTIand reconnect handshake behavior (CLIENT INFOdb).Reviewed by Cursor Bugbot for commit 809585f. Bugbot is set up for automated code reviews on this repo. Configure here.