New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MemCacheStore: always convert underlying values into an Entry
#42559
Merged
Conversation
This file contains 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
Hum, maybe? Best way to know is to check. |
byroot
approved these changes
Jun 22, 2021
CI failures seem totally unrelated. Your fix look good to me. Maybe we should add a regression test though? |
Good idea - regression test added. |
ghiculescu
commented
Jun 22, 2021
There's a bug in the Mem Cache Store on 6.1, I haven't confirmed if it exists on `main` too (since rails#42025). We came across the bug when upgrading an app from 6.0 to 6.1 that had recently switched from the `dalli_store` to the `mem_cache_store`. petergoldstein/dalli#771 seems similar, but in our case it's specifically to do with caching the value `false`. To replicate: - Open a Rails console with the `dalli_store` enabled. - `Rails.cache.write "test", false` - Open another Rails console, with the `mem_cache_store` enabled. - Enable the local cache (starting a Rails server would also achieve this): `ActiveSupport::Cache::Strategy::LocalCache::LocalCacheRegistry.set_cache_for(Rails.cache.send(:local_cache_key), ActiveSupport::Cache::Strategy::LocalCache::LocalStore.new)` - ` Rails.cache.fetch("test") { false }` It will crash with `NoMethodError (undefined method `dup_value!' for false:FalseClass)`. The fix is to convert any entry into an `Entry`, even if it's `nil` or `false`.
Regression test passes here. It fails on |
ghiculescu
added a commit
to ghiculescu/rails
that referenced
this pull request
Jun 22, 2021
Same bug as rails#42559, but a very different fix due to rails#42025. To recap, the issue: - While using the `dalli_store`, you set any value in the Rails cache with no expiry. - You change to the `mem_cache_store`. - You upgrade to Rails 7. - You try to read the same cache key you set in step 1, and it crashes on read. rails#42025 was backward compatible with entries written using the `mem_cache_store`, but *not* the `dalli_store` which did not use `ActiveSupport::Cache::Entry`. This PR attempts to fix that.
@ghiculescu @byroot Could you add a changelog? 🙇 |
ghiculescu
added a commit
to ghiculescu/rails
that referenced
this pull request
Jun 22, 2021
fatash89
approved these changes
Oct 1, 2021
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.
There's a bug in the Mem Cache Store on 6.1, I haven't confirmed if it exists on
main
too (since #42025).We came across the bug when upgrading an app from 6.0 to 6.1 that had recently switched from the
dalli_store
to themem_cache_store
. petergoldstein/dalli#771 seems similar, but in our case it's specifically to do with caching the valuefalse
.To replicate:
dalli_store
enabled.Rails.cache.write "test", false
mem_cache_store
enabled.ActiveSupport::Cache::Strategy::LocalCache::LocalCacheRegistry.set_cache_for(Rails.cache.send(:local_cache_key), ActiveSupport::Cache::Strategy::LocalCache::LocalStore.new)
Rails.cache.fetch("test") { false }
It will crash with
The fix is to convert any entry into an
Entry
, even if it'sfalse
.