aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-12-30 14:26:29 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-12-30 14:26:29 -0800
commit86729eb733ce67818f079744fdea5ec63e25259a (patch)
treef774b7e334375393ad866aee7941d5c1cb2f3765 /activerecord/lib
parente060cf01a5e05bc6eaeee90b8c421d2aa6435b7c (diff)
downloadrails-86729eb733ce67818f079744fdea5ec63e25259a.tar.gz
rails-86729eb733ce67818f079744fdea5ec63e25259a.tar.bz2
rails-86729eb733ce67818f079744fdea5ec63e25259a.zip
connections can be reaped via the `reap` method
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
index a88c9e2c4b..3f3b98ace0 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -232,6 +232,18 @@ module ActiveRecord
end
end
+ # Removes dead connections from the pool. A dead connection can occur
+ # if a programmer forgets to close a connection at the end of a thread
+ # or a thread dies unexpectedly.
+ def reap
+ synchronize do
+ stale = Time.now - @timeout
+ connections.dup.each do |conn|
+ remove conn if conn.in_use? && stale > conn.last_use
+ end
+ end
+ end
+
private
def new_connection