Skip to content

Commit 8a642ee

Browse files
committed
add back in double check on connection
1 parent 76ddbe7 commit 8a642ee

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

lib/fibered_mysql2/fibered_database_connection_pool.rb

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,6 @@ def with_connection
204204
def current_thread
205205
Fiber.current
206206
end
207-
208-
def connection
209-
cached_connections[current_connection_id] ||= checkout
210-
end
211207
end
212208

213209
if ::ActiveRecord.gem_version < "7.1"
@@ -243,6 +239,23 @@ def checkout(checkout_timeout = @checkout_timeout)
243239
end
244240
super
245241
end
242+
243+
# Invoca patch to ensure that we are using the current fiber's connection.
244+
def connection
245+
# this is correctly done double-checked locking
246+
# (ThreadSafe::Cache's lookups have volatile semantics)
247+
if (result = cached_connections[current_connection_id])
248+
result
249+
else
250+
synchronize do
251+
if (result = cached_connections[current_connection_id])
252+
result
253+
else
254+
cached_connections[current_connection_id] = checkout
255+
end
256+
end
257+
end
258+
end
246259
end
247260
end
248261

lib/fibered_mysql2/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module FiberedMysql2
4-
VERSION = "0.4.0.pre.tstarck.1"
4+
VERSION = "0.4.0.pre.tstarck.2"
55
end

0 commit comments

Comments
 (0)