Skip to content

Commit dcbb5c2

Browse files
committed
Conistently release the autoloading interlock from all adapters
Fix: rails#53871 In `007e50d8e5a900547471b6c4ec79d9d217682c5d` all adapters started wrapping DB calls with the interlock release. However in rails#44576, this was removed from all adapters but Mysql2. This commit restore the proper release on all adapters.
1 parent 5520bd8 commit dcbb5c2

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,9 @@ def raw_execute(sql, name = nil, binds = [], prepare: false, async: false, allow
553553
type_casted_binds = type_casted_binds(binds)
554554
log(sql, name, binds, type_casted_binds, async: async) do |notification_payload|
555555
with_raw_connection(allow_retry: allow_retry, materialize_transactions: materialize_transactions) do |conn|
556-
perform_query(conn, sql, binds, type_casted_binds, prepare: prepare, notification_payload: notification_payload, batch: batch)
556+
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
557+
perform_query(conn, sql, binds, type_casted_binds, prepare: prepare, notification_payload: notification_payload, batch: batch)
558+
end
557559
end
558560
end
559561
end

activerecord/lib/active_record/connection_adapters/mysql2/database_statements.rb

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,18 @@ def perform_query(raw_connection, sql, binds, type_casted_binds, prepare:, notif
5050

5151
result = nil
5252
if binds.nil? || binds.empty?
53-
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
54-
result = raw_connection.query(sql)
55-
# Ref: https://github.com/brianmario/mysql2/pull/1383
56-
# As of mysql2 0.5.6 `#affected_rows` might raise Mysql2::Error if a prepared statement
57-
# from that same connection was GCed while `#query` released the GVL.
58-
# By avoiding to call `#affected_rows` when we have a result, we reduce the likeliness
59-
# of hitting the bug.
60-
@affected_rows_before_warnings = result&.size || raw_connection.affected_rows
61-
end
53+
result = raw_connection.query(sql)
54+
# Ref: https://github.com/brianmario/mysql2/pull/1383
55+
# As of mysql2 0.5.6 `#affected_rows` might raise Mysql2::Error if a prepared statement
56+
# from that same connection was GCed while `#query` released the GVL.
57+
# By avoiding to call `#affected_rows` when we have a result, we reduce the likeliness
58+
# of hitting the bug.
59+
@affected_rows_before_warnings = result&.size || raw_connection.affected_rows
6260
elsif prepare
6361
stmt = @statements[sql] ||= raw_connection.prepare(sql)
6462
begin
65-
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
66-
result = stmt.execute(*type_casted_binds)
67-
@affected_rows_before_warnings = stmt.affected_rows
68-
end
63+
result = stmt.execute(*type_casted_binds)
64+
@affected_rows_before_warnings = stmt.affected_rows
6965
rescue ::Mysql2::Error
7066
@statements.delete(sql)
7167
raise
@@ -74,10 +70,8 @@ def perform_query(raw_connection, sql, binds, type_casted_binds, prepare:, notif
7470
stmt = raw_connection.prepare(sql)
7571

7672
begin
77-
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
78-
result = stmt.execute(*type_casted_binds)
79-
@affected_rows_before_warnings = stmt.affected_rows
80-
end
73+
result = stmt.execute(*type_casted_binds)
74+
@affected_rows_before_warnings = stmt.affected_rows
8175

8276
# Ref: https://github.com/brianmario/mysql2/pull/1383
8377
# by eagerly closing uncached prepared statements, we also reduce the chances of

0 commit comments

Comments
 (0)