Repository navigation
fix(hooks): don't let cache store a read that an invalidation overtook - #79
Merged
Merged
Conversation
A `get`/`find` that missed the cache and was still reading while a write invalidated the cache stored its result afterwards - a result that may predate the write, bringing back what the invalidation removed until the entry was evicted or its `ttl` ran out. Every invalidation now bumps a generation counter. A miss remembers the generation it started reading in, and `set` only stores the result if no invalidation ran in between. Hits are still not stored again; they are simply no longer tracked, since only misses are. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Deploying feathers-utils with
|
| Latest commit: |
f9022dd
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://5c242744.feathers-utils.pages.dev |
| Branch Preview URL: | https://fix-cache-stale-read-after-i.feathers-utils.pages.dev |
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.
A
get/findthat missed the cache and was still reading while a write invalidated the cache stored its result afterwards. That result may predate the write, so it brought back what the invalidation had removed, and the stale entry stayed until it was evicted or itsttlran out.cacheHook.invalidate) bumps a generation counter.setonly stores the result if no invalidation ran in between.WeakMapthat replaces thehitsWeakSet.Tests: two new cases hold a slow
findbetween the database and the cache while a write runs, once throughcreateand once throughinvalidate. One existing test now shares a single context between before and after, as a real call does.🤖 Generated with Claude Code