Permalink
Browse files

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

Synchronize read and modification of @reserved_connections
  • Loading branch information...
tenderlove committed May 19, 2012
1 parent d641646 commit 879611f50c76f79258e5925de113d9f8f8a5b418
Showing with 8 additions and 4 deletions.
  1. +8 −4 activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -92,14 +92,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 879611f

Please sign in to comment.