Skip to content

Commit 879611f

Browse files
committed
Merge pull request rails#6398 from pmahoney/threadsafe-connection-pool
Synchronize read and modification of @reserved_connections
1 parent d641646 commit 879611f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,18 @@ def initialize(spec)
9292
# #connection can be called any number of times; the connection is
9393
# held in a hash keyed by the thread id.
9494
def connection
95-
@reserved_connections[current_connection_id] ||= checkout
95+
synchronize do
96+
@reserved_connections[current_connection_id] ||= checkout
97+
end
9698
end
9799

98100
# Is there an open connection that is being used for the current thread?
99101
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
103107
end
104108

105109
# Signal that the thread is finished with the current connection.

0 commit comments

Comments
 (0)