Skip to content
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

undefined method `dup_value!' with dalli 2.7.11 and rails 6.1 #771

Closed
roccoblues opened this issue Jan 6, 2021 · 13 comments
Closed

undefined method `dup_value!' with dalli 2.7.11 and rails 6.1 #771

roccoblues opened this issue Jan 6, 2021 · 13 comments

Comments

@roccoblues
Copy link

A simple Rails.cache.write with :dalli_store and Rails 6.1 leads to undefined method dup_value!'`.

I tracked it down to this commit in rails: rails/rails@9b09187#diff-ec46f57f15b817f91efebde97d0e74edfc656ada553296cecdf09a9611d95bf5

There was also an issue opened in rails reporting the same problem: rails/rails#40869

Is dalli 2.x supposed to support rails 6.1?

@petergoldstein
Copy link
Owner

@roccoblues So Dalli 2.x wasn't validated against Rails 6.1. Is there a reason you don't want to use MemCacheStore?

@roccoblues
Copy link
Author

Hi @petergoldstein, we're using an internal gem that builds on DalliStore. We tried to switch that to MemCacheStore but had to rollback due to a huge increase (allocated bytes doubled) in allocations when we switched. We haven't investigated further but the theory is that that comes from the fact that MemCacheStore wraps every cache data into an additional ActiveSupport::Cache::Entry object.

patbl added a commit to academia-edu/cached_counts that referenced this issue Jan 12, 2021
DalliStore isn't supported in Rails 6.1 or Dalli 3.0; see
petergoldstein/dalli#771.
thomasleese added a commit to alphagov/local-links-manager that referenced this issue Jan 14, 2021
This fixes an issue where the Dalli store is not supported in Rails 6.1:
petergoldstein/dalli#771
thomasleese added a commit to alphagov/local-links-manager that referenced this issue Jan 14, 2021
This fixes an issue where the Dalli store is not supported in Rails 6.1:
petergoldstein/dalli#771
thomasleese added a commit to alphagov/local-links-manager that referenced this issue Jan 14, 2021
This fixes an issue where the Dalli store is not supported in Rails 6.1:
petergoldstein/dalli#771
@ssherman
Copy link

I am having this same problem. Switching to the mem_cache_store in the mean time.

@qrush
Copy link

qrush commented Feb 2, 2021

Also running into this during a Rails 6.1 upgrade and didn't discover it until we got it out on our staging server.

@petergoldstein should there be a 2.7.12 released that is pinned to Rails < 6.1 ? And then maybe 2.8 can introduce 6.1 compat?

Relative stack trace here, coming from a Rails.cache.fetch block:

vendor/bundle/ruby/2.6.0/bundler/gems/rails-9f39d00ed29f/activesupport/lib/active_support/cache/strategy/local_cache.rb:68:in `write_entry': undefined method `dup_value!' for false:FalseClass (NoMethodError)
    from vendor/bundle/ruby/2.6.0/bundler/gems/rails-9f39d00ed29f/activesupport/lib/active_support/cache/strategy/local_cache.rb:162:in `write_entry'
    from vendor/bundle/ruby/2.6.0/gems/dalli-2.7.9/lib/active_support/cache/dalli_store.rb:145:in `block (2 levels) in write'
    from vendor/bundle/ruby/2.6.0/gems/dalli-2.7.9/lib/dalli/client.rb:266:in `with'
    from vendor/bundle/ruby/2.6.0/gems/dalli-2.7.9/lib/active_support/cache/dalli_store.rb:83:in `with'
    from vendor/bundle/ruby/2.6.0/gems/dalli-2.7.9/lib/active_support/cache/dalli_store.rb:143:in `block in write'
    from vendor/bundle/ruby/2.6.0/gems/dalli-2.7.9/lib/active_support/cache/dalli_store.rb:386:in `block in instrument_with_log'
    from vendor/bundle/ruby/2.6.0/gems/dalli-2.7.9/lib/active_support/cache/dalli_store.rb:395:in `block in instrument'
    from vendor/bundle/ruby/2.6.0/bundler/gems/rails-9f39d00ed29f/activesupport/lib/active_support/notifications.rb:205:in `instrument'
    from vendor/bundle/ruby/2.6.0/gems/dalli-2.7.9/lib/active_support/cache/dalli_store.rb:394:in `instrument'
    from vendor/bundle/ruby/2.6.0/gems/dalli-2.7.9/lib/active_support/cache/dalli_store.rb:386:in `instrument_with_log'
    from vendor/bundle/ruby/2.6.0/gems/dalli-2.7.9/lib/active_support/cache/dalli_store.rb:142:in `write'
    from vendor/bundle/ruby/2.6.0/gems/dalli-2.7.9/lib/active_support/cache/dalli_store.rb:116:in `fetch'

@alexisraca
Copy link

alexisraca commented Feb 25, 2021

Having the same problem with rails 6.1.3

EDIT: Can anyone elaborate on what's the plan for this bug? It is preventing us from upgrading to rails 6 and dalli_store is a cornerstone of our sytem.

I noticed that dalli 3.0 is going to deprecate dalli_store so is this bug even planned to be fixed in <= 2.X.X?

ChrisBAshton added a commit to alphagov/collections that referenced this issue Mar 19, 2021
Dalli store is not supported in Rails 6.1:
petergoldstein/dalli#771

The fix is to swap out for MemCacheStore, as we've done here:
alphagov/local-links-manager#751

Without this change, a write to the cache causes this exception:

```
NoMethodError
undefined method `dup_value!' for #<String:0x00007f9cf66fb130>
```

That said, we still need the dalli gem, otherwise we get this
error:

```
Could not find cache store adapter for mem_cache_store (cannot load such file -- dalli)
/app/config/environment.rb:5:in `<top (required)>'
```
@alexisraca
Copy link

For anyone having this problem:

  • we changed to mem_cache_store which solved the bug
  • Then we found another bug about "undefined method get_multi_cas"

If you are using identity_cache on the latest tag, there is a bugfix in this commit mperham/connection_pool@97b2698 right above the top tag.

it is related to the connection_pool configuration.

@ghiculescu
Copy link

We had this issue happen after switching to the mem_cache_store if the value false was cached anywhere. For now we are rolling cache keys where this is likely, but have also proposed a fix in Rails: rails/rails#42559

ghiculescu added a commit to ghiculescu/rails that referenced this issue 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`.
benjamineskola added a commit to alphagov/government-frontend that referenced this issue Jul 29, 2021
This fixes an issue where the Dalli store is not supported in Rails 6.1: petergoldstein/dalli#771, cf. alphagov/local-links-manager#751 and alphagov/collections#2287
benjamineskola added a commit to alphagov/government-frontend that referenced this issue Jul 29, 2021
This fixes an issue where the Dalli store is not supported in Rails 6.1: petergoldstein/dalli#771, cf. alphagov/local-links-manager#751 and alphagov/collections#2287
@zhengpd
Copy link

zhengpd commented Aug 23, 2021

undefined method `dup_value!' with dalli 2.7.11 and rails 6.1

Saw this when using :dalli_store. After switched to :mem_cache_store the error is gone.

@petergoldstein
Copy link
Owner

@ghiculescu Now that your fix in Rails is merged, is there anything additional to be fixed in Dalli to address this issue?

@ghiculescu
Copy link

My issue wasn’t exactly the same as OP’s, but no, my gut feel is this issue can be resolved. @byroot and I shipped a few rails PRs for backward compat around the local cache.

@petergoldstein
Copy link
Owner

@alexisraca Apologies for the late reply, but we're not planning to do any additional support work for :dalli_store.

Are all your post-switch issues resolved, or do you believe additional items need to be fixed in Dalli?

@alexisraca
Copy link

alexisraca commented Nov 11, 2021

@petergoldstein Everything is cool now. The fixes posted in my last comment solved everything. There was a bug in our implementation with identity_cache which was solved by a commit above the top tag. Thank you!.

@petergoldstein
Copy link
Owner

Thanks @alexisraca .

Closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants