Skip to content

Synchronize the body of the ConnectionPool#release method to improve thread safety. #6467

Merged
merged 1 commit into from May 23, 2012
View
22 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
Something went wrong with that request. Please try again.