Skip to content
Browse files

Merge pull request #6398 from pmahoney/threadsafe-connection-pool

Synchronize read and modification of @reserved_connections
  • Loading branch information...
2 parents 777d539 + c2d416f commit 23fad29c1932119898259eab557162c1326fd325 @tenderlove tenderlove committed May 19, 2012
Showing with 8 additions and 4 deletions.
  1. +8 −4 activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
View
12 activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -139,14 +139,18 @@ def initialize(spec)
# #connection can be called any number of times; the connection is
# held in a hash keyed by the thread id.
def connection
- @reserved_connections[current_connection_id] ||= checkout
+ synchronize do
+ @reserved_connections[current_connection_id] ||= checkout
+ end
end
# Is there an open connection that is being used for the current thread?
def active_connection?
- @reserved_connections.fetch(current_connection_id) {
- return false
- }.in_use?
+ synchronize do
+ @reserved_connections.fetch(current_connection_id) {
+ return false
+ }.in_use?
+ end
end
# Signal that the thread is finished with the current connection.

0 comments on commit 23fad29

Please sign in to comment.
Something went wrong with that request. Please try again.