Repository navigation
fix(client): empty the client-side cache when SELECT is issued, not on its reply - #3661
Closed
Cdineshreddy12 wants to merge 1 commit into
Closed
Cdineshreddy12 wants to merge 1 commit into
Cdineshreddy12 wants to merge 1 commit into
Conversation
…n its reply Cache keys do not include the database, so a cacheable read issued after select(db) but before its reply was served the previous database's cached value: handleCache() consults the cache synchronously at command time, while #setSelectedDB — which empties the cache on a database change — only ran once the SELECT reply arrived. Empty the cache the moment SELECT is issued, only when the database actually changes. #setSelectedDB still empties it on the reply for the pipeline/MULTI SELECT paths, which cannot invalidate at issue time. Selecting the already-selected database leaves the cache intact.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Collaborator
|
Closing this. The race only shows up when a read is sent before |
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.
Cache keys do not include the database, so a cacheable read issued after
select(db)but before its reply was served the previous database's cached value:handleCache()consults the cache synchronously at command time, while the empty-on-database-change ran only once theSELECTreply arrived (#setSelectedDB).This empties the cache the moment
SELECTis issued, and only when the database actually changes.#setSelectedDBstill empties it on the reply for the pipeline/MULTISELECTpaths, which cannot invalidate at issue time. Selecting the already-selected database leaves the cache intact.Same cross-database concern as #3641 (which empties the cache on a database change) — this closes the residual window where a read races the in-flight
SELECT.Added a unit test (never-connected client) asserting the cache clears synchronously at issue time rather than on the reply.
Note
Medium Risk
Changes client-side caching correctness around database switches; limited scope but can affect apps that interleave SELECT with cached reads.
Overview
Fixes a stale client-side cache race: cache keys omit the database index, so a cacheable read issued after
select(newDb)but before theSELECTreply could still return a value cached from the previous database.SELECTnow callsinvalidate(null)synchronously when the target database differs from the current one, beforesendCommandruns. Selecting the database that is already active leaves the cache unchanged.#setSelectedDBon the reply still clears the cache for pipeline/MULTISELECTpaths that cannot invalidate at issue time.Adds a unit test using a never-connected client to assert the cache is empty immediately after
select()is issued, without waiting for a reply.Reviewed by Cursor Bugbot for commit f0bb6b2. Bugbot is set up for automated code reviews on this repo. Configure here.