aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
diff options
context:
space:
mode:
authorPatrick Mahoney <pat@polycrystal.org>2012-05-19 11:45:55 -0500
committerPatrick Mahoney <pat@polycrystal.org>2012-05-19 11:46:58 -0500
commitc2d416fe7712cbaf69036f9e638c825e08415e34 (patch)
tree18a87a531e4ef3d7811237175f617c92e5f78141 /activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
parent777d53901427ea183170c932d27eb43ce9fa5800 (diff)
downloadrails-c2d416fe7712cbaf69036f9e638c825e08415e34.tar.gz
rails-c2d416fe7712cbaf69036f9e638c825e08415e34.tar.bz2
rails-c2d416fe7712cbaf69036f9e638c825e08415e34.zip
Synchronize read and modification of @reserved_connections hash to avoid concurrency error.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb12
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 46c7fc71ac..c6699737b4 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -139,14 +139,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.