Permalink
Browse files

Merge pull request #6467 from aselder/3-2-stable

Synchronize the body of the ConnectionPool#release method to improve thread safety.
  • Loading branch information...
2 parents ff3cddf + e663aa3 commit 356f2a6d8b3bb48b9c7d7508de932121d0e013bb @tenderlove tenderlove committed May 23, 2012
Showing with 12 additions and 10 deletions.
  1. +12 −10 activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -290,17 +290,19 @@ def checkin(conn)
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

0 comments on commit 356f2a6

Please sign in to comment.