Skip to content
This repository
Browse code

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

Synchronize read and modification of @reserved_connections
  • Loading branch information...
commit 879611f50c76f79258e5925de113d9f8f8a5b418 1 parent d641646
Aaron Patterson tenderlove authored
12 activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -92,14 +92,18 @@ def initialize(spec)
92 92 # #connection can be called any number of times; the connection is
93 93 # held in a hash keyed by the thread id.
94 94 def connection
95   - @reserved_connections[current_connection_id] ||= checkout
  95 + synchronize do
  96 + @reserved_connections[current_connection_id] ||= checkout
  97 + end
96 98 end
97 99
98 100 # Is there an open connection that is being used for the current thread?
99 101 def active_connection?
100   - @reserved_connections.fetch(current_connection_id) {
101   - return false
102   - }.in_use?
  102 + synchronize do
  103 + @reserved_connections.fetch(current_connection_id) {
  104 + return false
  105 + }.in_use?
  106 + end
103 107 end
104 108
105 109 # Signal that the thread is finished with the current connection.

0 comments on commit 879611f

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