Skip to content

Commit

Permalink
Don't auto-create connection if nil on methods
Browse files Browse the repository at this point in the history
Unless told otherwhise, when this proxy class intercepts methods, it will create
a connection if one does not already exist.

https://github.com/zendesk/active_record_host_pool/blob/v0.11.0/lib/active_record_host_pool/pool_proxy.rb#L107-L108

In Rails 5.2.0, they added the following functionality which caused issues with
code mentioned above
https://github.com/rails/rails/blob/v5.2.3/activerecord/lib/active_record/railtie.rb#L180-L195

Here's the associated PRs
rails/rails#28057
rails/rails#31221

This patch overrides the methods, retrieves the connection if it's active and
calls super without creating a new one.

This resolves an issue for applications upgrading to Rails 5.2.3 whereby
connections would be created and thrown away during Rails.application.initialize!
  • Loading branch information
mriddle committed Aug 22, 2019
1 parent 5d7367f commit 5916c96
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/active_record_host_pool/pool_proxy.rb
Expand Up @@ -84,6 +84,28 @@ def clear_reloadable_connections!
_clear_connection_proxy_cache
end

def release_connection(owner_thread = Thread.current)
p = _connection_pool(false)
return unless p

p.release_connection(owner_thread)
end

def flush!
p = _connection_pool(false)
return unless p

p.reap
p.flush(-1)
end

def discard!
p = _connection_pool(false)
return unless p

p.discard!
end

private

def rescuable_errors
Expand Down

0 comments on commit 5916c96

Please sign in to comment.