Prevent getNodeByQuery from leaking DB changes into client#2206
Merged
zuiderkwast merged 2 commits intoJun 16, 2025
Merged
Conversation
To support multiple databases in cluster mode (see valkey-io#1671), `getNodeByQuery` temporarily switches databases when tracking `SELECT` statements during slot migration/import. The intended logic is to revert any database change after the operation. However, this approach is flawed: in some transactions the database change is not properly reverted, causing the client to remain on the wrong database. For example, if a transaction includes `SELECT` statements, the current database may be changed even if the transaction is never executed (see added test). Fix the issue by saving the original database once and restoring to it after a switch. Signed-off-by: Simon Baatz <gmbnomis@gmail.com>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## unstable #2206 +/- ##
============================================
+ Coverage 71.50% 71.56% +0.05%
============================================
Files 122 122
Lines 66493 66493
============================================
+ Hits 47547 47585 +38
+ Misses 18946 18908 -38
🚀 New features to boost your workflow:
|
zuiderkwast
approved these changes
Jun 12, 2025
Co-authored-by: Viktor Söderqvist <viktor.soderqvist@est.tech> Signed-off-by: Simon Baatz <gmbnomis@users.noreply.github.com>
ranshid
pushed a commit
to ranshid/valkey
that referenced
this pull request
Jun 18, 2025
…#2206) To support multiple databases in cluster mode (see valkey-io#1671), `getNodeByQuery` temporarily switches databases when tracking `SELECT` statements during slot migration/import. The intended logic is to revert any database change after the operation. However, this approach is flawed: in some transactions the database change is not properly reverted, causing the client to remain on the wrong database. For example, if a transaction includes `SELECT` statements, the current database may be changed even if the transaction is never executed (see added test). Fix the issue by saving the original database once and restoring to it after a switch. --------- Signed-off-by: Simon Baatz <gmbnomis@gmail.com> Signed-off-by: Simon Baatz <gmbnomis@users.noreply.github.com> Co-authored-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
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.
To support multiple databases in cluster mode (see #1671),
getNodeByQuerytemporarily switches databases when trackingSELECTstatements during slot migration/import. The intended logic is to revert any database change after the operation. However, this approach is flawed: in some transactions the database change is not properly reverted, causing the client to remain on the wrong database.For example, if a transaction includes
SELECTstatements, the current database may be changed even if the transaction is never executed (see added test).Fix the issue by saving the original database once and restoring to it after a switch.