Skip to content

PoolConfig caches the connection_class, which breaks if it is reloaded #54343

@djmb

Description

@djmb

I've been debugging this Solid Cache issue, and it looks like it is caused by reloading the connection class.

It is stored in the ActiveRecord::ConnectionAdapters::PoolConfig, and if the connection class is reloaded, then
it no longer matches the stored value.

This breaks checks like this, leading to issues like the one we see in the Solid Cache bug.

You can reproduce in a development console if you are using Solid Cache like this:

>> ActiveRecord::Base.connected_to(role: ActiveRecord.reading_role, prevent_writes: true) do 
  SolidCache::Record.connected_to(shard: :cache, role: :writing, prevent_writes: false) do
     puts SolidCache::Record.connection.preventing_writes?
  end
end
false
=> nil
>> reload!
Reloading...
>> ActiveRecord::Base.connected_to(role: ActiveRecord.reading_role, prevent_writes: true) do 
  SolidCache::Record.connected_to(shard: :cache, role: :writing, prevent_writes: false) do
     puts SolidCache::Record.connection.preventing_writes?
  end
end
true
=> nil
>>

I can fix this specifically for Solid Cache by preventing SolidCache::Record from being reloaded, but this could still be an issue for any application specific connection classes.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions