diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-05-19 11:39:17 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-05-19 11:50:47 -0700 |
commit | 879611f50c76f79258e5925de113d9f8f8a5b418 (patch) | |
tree | 1af5a5d79be06f1d4f02f54fbcf1881df6a568b4 | |
parent | d64164645d435e22fdab8179481acb89827dfe68 (diff) | |
download | rails-879611f50c76f79258e5925de113d9f8f8a5b418.tar.gz rails-879611f50c76f79258e5925de113d9f8f8a5b418.tar.bz2 rails-879611f50c76f79258e5925de113d9f8f8a5b418.zip |
Merge pull request #6398 from pmahoney/threadsafe-connection-pool
Synchronize read and modification of @reserved_connections
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb index 3af285c7c8..f44cba3978 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -92,14 +92,18 @@ module ActiveRecord # #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. |