Repository navigation
Flush idle database connections - #31221
Conversation
288d5f6 to
6802b48
Compare
|
Great work 👏 |
|
Nice! appreciate it! will be happy to let go of our monkey patch |
6802b48 to
9027faf
Compare
|
Awesome @matthewd! |
|
@matthewd question: There is this behavior:
And this behavior:
So in the "in case it did" scenario, if the puma (say) process forks are done sooner than 60 seconds after a connection was used, will the pre-fork process fail to let go of all connections before forking? |
|
@jjb no; that calls
(and any accidentally-checked-out connection will first be returned to the pool by |
|
Thanks. I've confirmed that 5.2.0.rc1 makes one instance of my connection management code unnecessary. Interestingly there was another instance, described in the spawning processes example, where I couldn't reproduce a problem in any version of rails. I'm not sure if I ever experienced it there or if I was just adding the management to be on the safe side. The place where I did require the management, and now in 5.2 do not, was inside of an AR model (in a class method). So maybe there's something different about forking in a standalone script (run with shrug emoticon. |
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!
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!
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!
After #28742, this seems to be a plausible much simpler take on #23815.
This is actually two features:
on_loadhook, which ensures a Puma master process doesn't keep a connection open just because it needed one during boot. (Slightly related to Improve AR connection fork safety #31173, but separate: that one's about being safer if we do keep the connection; this is about not keeping the connection at all if we don't need it.)