diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-05-23 13:23:59 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-05-23 13:23:59 -0700 |
commit | 356f2a6d8b3bb48b9c7d7508de932121d0e013bb (patch) | |
tree | b5fde51c08b212c7fec13d29ff50b1973f845eb9 /activerecord | |
parent | ff3cddf8763e100947cdffe9c25716e93ccbac62 (diff) | |
parent | e663aa39aa8599f01cce2f61c68e8bea736fc186 (diff) | |
download | rails-356f2a6d8b3bb48b9c7d7508de932121d0e013bb.tar.gz rails-356f2a6d8b3bb48b9c7d7508de932121d0e013bb.tar.bz2 rails-356f2a6d8b3bb48b9c7d7508de932121d0e013bb.zip |
Merge pull request #6467 from aselder/3-2-stable
Synchronize the body of the ConnectionPool#release method to improve thread safety.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb | 22 |
1 files changed, 12 insertions, 10 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 f44cba3978..d4649102df 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -290,17 +290,19 @@ connection. For example: ActiveRecord::Base.connection.close private def release(conn) - thread_id = nil - - if @reserved_connections[current_connection_id] == conn - thread_id = current_connection_id - else - thread_id = @reserved_connections.keys.find { |k| - @reserved_connections[k] == conn - } - end + synchronize do + thread_id = nil + + if @reserved_connections[current_connection_id] == conn + thread_id = current_connection_id + else + thread_id = @reserved_connections.keys.find { |k| + @reserved_connections[k] == conn + } + end - @reserved_connections.delete thread_id if thread_id + @reserved_connections.delete thread_id if thread_id + end end def new_connection |