Skip to content

Commit 5916c96

Browse files
committed
Don't auto-create connection if nil on methods
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!
1 parent 5d7367f commit 5916c96

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

lib/active_record_host_pool/pool_proxy.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,28 @@ def clear_reloadable_connections!
8484
_clear_connection_proxy_cache
8585
end
8686

87+
def release_connection(owner_thread = Thread.current)
88+
p = _connection_pool(false)
89+
return unless p
90+
91+
p.release_connection(owner_thread)
92+
end
93+
94+
def flush!
95+
p = _connection_pool(false)
96+
return unless p
97+
98+
p.reap
99+
p.flush(-1)
100+
end
101+
102+
def discard!
103+
p = _connection_pool(false)
104+
return unless p
105+
106+
p.discard!
107+
end
108+
87109
private
88110

89111
def rescuable_errors

0 commit comments

Comments
 (0)