From 463e6d7b4945c9f5c99c56c5e57d142f881dde43 Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 24 Sep 2021 07:59:57 -0500 Subject: [PATCH] artists: fix deadlock when banning artists. Caused by d854bf6b. Banning an artist would deadlock because it was performed in a transaction, which didn't work with the `parallel_each` inside the "create an implication to banned_artist" step. --- app/models/application_record.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 502af8603..42c33a876 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -169,6 +169,9 @@ class ApplicationRecord < ActiveRecord::Base concerning :ConcurrencyMethods do class_methods do def parallel_each(batch_size: 1000, in_processes: 4, in_threads: nil, &block) + # XXX We may deadlock if a transaction is open; do a non-parallel each. + return find_each(&block) if connection.transaction_open? + # XXX Use threads in testing because processes can't see each other's # database transactions. if Rails.env.test? @@ -176,9 +179,6 @@ class ApplicationRecord < ActiveRecord::Base in_threads = 2 end - # XXX Threads deadlock during tests if a transaction is open; do a non-parallel each. - return find_each(&block) if Rails.env.test? && connection.transaction_open? - current_user = CurrentUser.user current_ip = CurrentUser.ip_addr