diff options
author | Hemant Kumar <hkumar@crri.co.in> | 2010-09-30 12:12:23 +0530 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-10-06 14:45:56 -0600 |
commit | 2a04110f266b6ccaf94aeeae224af578a9620fbd (patch) | |
tree | bb9c08186fddbe3af7063faff9e478d0098f0c6f /activerecord/lib/active_record | |
parent | a0552d653b00e2e5b77e086b155e89fa22e4d6ed (diff) | |
download | rails-2a04110f266b6ccaf94aeeae224af578a9620fbd.tar.gz rails-2a04110f266b6ccaf94aeeae224af578a9620fbd.tar.bz2 rails-2a04110f266b6ccaf94aeeae224af578a9620fbd.zip |
fix ruby 1.9 deadlock problem, fixes #5736 add connection pool tests
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb | 14 |
1 files changed, 6 insertions, 8 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 37e584a629..0c264de869 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -75,10 +75,7 @@ module ActiveRecord @queue = @connection_mutex.new_cond # default 5 second timeout unless on ruby 1.9 - @timeout = - if RUBY_VERSION < '1.9' - spec.config[:wait_timeout] || 5 - end + @timeout = spec.config[:wait_timeout] || 5 # default max pool size to 5 @size = (spec.config[:pool] && spec.config[:pool].to_i) || 5 @@ -161,7 +158,6 @@ module ActiveRecord keys = @reserved_connections.keys - Thread.list.find_all { |t| t.alive? }.map { |thread| thread.object_id } - keys.each do |key| checkin @reserved_connections[key] @reserved_connections.delete(key) @@ -194,16 +190,18 @@ module ActiveRecord checkout_new_connection end return conn if conn - # No connections available; wait for one - if @queue.wait(@timeout) + + @queue.wait(@timeout) + + if(@checked_out.size < @connections.size) next else - # try looting dead threads clear_stale_cached_connections! if @size == @checked_out.size raise ConnectionTimeoutError, "could not obtain a database connection#{" within #{@timeout} seconds" if @timeout}. The max pool size is currently #{@size}; consider increasing it." end end + end end end |