aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/railtie.rb
diff options
context:
space:
mode:
authorEugene Kenny <elkenny@gmail.com>2017-02-17 23:56:48 +0000
committerEugene Kenny <elkenny@gmail.com>2017-02-17 23:56:48 +0000
commitb66b5378baf3804e9985a7cb9630f6d5a3ddcf97 (patch)
tree17880316f7a265d9f04003a4a2edcf694cf62423 /activerecord/lib/active_record/railtie.rb
parentc059caab7bcf40dec4902ac21cef673625da2a24 (diff)
downloadrails-b66b5378baf3804e9985a7cb9630f6d5a3ddcf97.tar.gz
rails-b66b5378baf3804e9985a7cb9630f6d5a3ddcf97.tar.bz2
rails-b66b5378baf3804e9985a7cb9630f6d5a3ddcf97.zip
Clear active connections after initialization
Any connections that were checked out during initialization should be checked back in before the first request is processed, for two reasons: - Returning the connection to the pool allows it to be health checked before it's used again. If the connection dies before the first request arrives, the health check will replace it with a new one. - If the thread that initialized Rails is not the same thread that will be performing work, checking in the connection will allow it to be reused instead of being stuck to the initialization thread forever.
Diffstat (limited to 'activerecord/lib/active_record/railtie.rb')
-rw-r--r--activerecord/lib/active_record/railtie.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/railtie.rb b/activerecord/lib/active_record/railtie.rb
index 0276d41494..73518ca144 100644
--- a/activerecord/lib/active_record/railtie.rb
+++ b/activerecord/lib/active_record/railtie.rb
@@ -166,5 +166,13 @@ end_warning
path = app.paths["db"].first
config.watchable_files.concat ["#{path}/schema.rb", "#{path}/structure.sql"]
end
+
+ initializer "active_record.clear_active_connections" do
+ config.after_initialize do
+ ActiveSupport.on_load(:active_record) do
+ clear_active_connections!
+ end
+ end
+ end
end
end