diff --git a/config/initializers/01_redis.rb b/config/initializers/01_redis.rb index 664dcd435..93c12fce7 100644 --- a/config/initializers/01_redis.rb +++ b/config/initializers/01_redis.rb @@ -1,3 +1,7 @@ +# TODO: Phase out the custom ConnectionPool wrappers ($alfred / $velma), +# switch to plain Redis clients here and let Rails 7.1+ handle pooling +# via `pool:` in RedisCacheStore (see rack_attack initializer). + # Alfred # Add here as you use it for more features # Used for Round Robin, Conversation Emails & Online Presence diff --git a/config/initializers/rack_attack.rb b/config/initializers/rack_attack.rb index fdbd47008..fe3f6c554 100644 --- a/config/initializers/rack_attack.rb +++ b/config/initializers/rack_attack.rb @@ -11,7 +11,12 @@ class Rack::Attack # Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new # https://github.com/rack/rack-attack/issues/102 - Rack::Attack.cache.store = ActiveSupport::Cache::RedisCacheStore.new(redis: $velma) + # Rails 7.1 automatically adds its own ConnectionPool around RedisCacheStore. + # Because `$velma` is *already* a ConnectionPool, double-wrapping causes + # Redis calls like `get` to hit the outer wrapper and explode. + # `pool: false` tells Rails to skip its internal pool and use ours directly. + # TODO: We can use build in connection pool in future upgrade + Rack::Attack.cache.store = ActiveSupport::Cache::RedisCacheStore.new(redis: $velma, pool: false) class Request < ::Rack::Request # You many need to specify a method to fetch the correct remote IP address