File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff 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
247260end
248261
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
33module FiberedMysql2
4- VERSION = "0.4.0.pre.tstarck.1 "
4+ VERSION = "0.4.0.pre.tstarck.2 "
55end
You can’t perform that action at this time.
0 commit comments