mperham / connection_pool

Generic connection pooling for Ruby
MIT License
1.63k stars 143 forks source link

undefined method `set' for an instance of ConnectionPool #185

Closed afuno closed 4 months ago

afuno commented 8 months ago

When trying to update the project to Rails 7.1, the following problems began to arise in RSpec:

undefined method `set' for an instance of ConnectionPool

This occurs due to the call to the clear method in cache.clear. And cache in turn has this code:

cache = ActiveSupport::Cache::RedisCacheStore.new(
  redis: CurrentRedis.connection_pool,
  namespace: ...,
  expires_in: ...
)

connection_pool is:

@connection_pool ||= ConnectionPool.new(size: ..., timeout: ...) do
  Redis.new(**redis_args)
end

Please tell me, is this a problem in the configuration on my side or is it a problem in the ConnectionPool, which cannot work correctly in Rails 7.1? If the problem is in the configuration, then tell me how to fix it?

afuno commented 4 months ago

@mperham up

mperham commented 4 months ago

We need the backtrace.

afuno commented 4 months ago
Unexpected error NoMethodError: undefined method `get' for an instance of ConnectionPool
Backtrace:
/Users/afuno/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/activesupport-7.1.3.4/lib/active_support/cache/redis_cache_store.rb:320:in `block (2 levels) in read_serialized_entry'
/Users/afuno/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/connection_pool-2.4.1/lib/connection_pool.rb:110:in `block (2 levels) in with'
/Users/afuno/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/connection_pool-2.4.1/lib/connection_pool.rb:109:in `handle_interrupt'
/Users/afuno/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/connection_pool-2.4.1/lib/connection_pool.rb:109:in `block in with'
/Users/afuno/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/connection_pool-2.4.1/lib/connection_pool.rb:106:in `handle_interrupt'
/Users/afuno/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/connection_pool-2.4.1/lib/connection_pool.rb:106:in `with'
/Users/afuno/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/activesupport-7.1.3.4/lib/active_support/cache/redis_cache_store.rb:320:in `block in read_serialized_entry'
/Users/afuno/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/activesupport-7.1.3.4/lib/active_support/cache/redis_cache_store.rb:479:in `failsafe'
/Users/afuno/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/activesupport-7.1.3.4/lib/active_support/cache/redis_cache_store.rb:319:in `read_serialized_entry'
/Users/afuno/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/activesupport-7.1.3.4/lib/active_support/cache/strategy/local_cache.rb:130:in `read_serialized_entry'
/Users/afuno/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/activesupport-7.1.3.4/lib/active_support/cache/redis_cache_store.rb:315:in `read_entry'
/Users/afuno/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/activesupport-7.1.3.4/lib/active_support/cache.rb:512:in `block in read'
/Users/afuno/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/activesupport-7.1.3.4/lib/active_support/cache.rb:1030:in `block in _instrument'
/Users/afuno/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/activesupport-7.1.3.4/lib/active_support/notifications.rb:206:in `block in instrument'
/Users/afuno/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/activesupport-7.1.3.4/lib/active_support/notifications/instrumenter.rb:58:in `instrument'
/Users/afuno/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/activesupport-7.1.3.4/lib/active_support/notifications.rb:206:in `instrument'
/Users/afuno/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/activesupport-7.1.3.4/lib/active_support/cache.rb:1029:in `_instrument'
/Users/afuno/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/activesupport-7.1.3.4/lib/active_support/cache.rb:1006:in `instrument'
/Users/afuno/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/activesupport-7.1.3.4/lib/active_support/cache.rb:511:in `read'
mperham commented 4 months ago

I would suggest you configure the cache store per the docs, not manually creating things.

https://guides.rubyonrails.org/caching_with_rails.html#activesupport-cache-rediscachestore