diff options
-rw-r--r-- | changelogs/unreleased/fix-sidekiq-transaction-check-race.yml | 5 | ||||
-rw-r--r-- | config/initializers/forbid_sidekiq_in_transactions.rb | 13 |
2 files changed, 12 insertions, 6 deletions
diff --git a/changelogs/unreleased/fix-sidekiq-transaction-check-race.yml b/changelogs/unreleased/fix-sidekiq-transaction-check-race.yml new file mode 100644 index 00000000000..89ae4abfe11 --- /dev/null +++ b/changelogs/unreleased/fix-sidekiq-transaction-check-race.yml @@ -0,0 +1,5 @@ +--- +title: Fix race in forbid_sidekiq_in_transactions.rb +merge_request: 30359 +author: +type: fixed diff --git a/config/initializers/forbid_sidekiq_in_transactions.rb b/config/initializers/forbid_sidekiq_in_transactions.rb index a69f1ba090e..bb190af60b5 100644 --- a/config/initializers/forbid_sidekiq_in_transactions.rb +++ b/config/initializers/forbid_sidekiq_in_transactions.rb @@ -2,15 +2,16 @@ module Sidekiq module Worker EnqueueFromTransactionError = Class.new(StandardError) - mattr_accessor :skip_transaction_check - self.skip_transaction_check = false - def self.skipping_transaction_check(&block) - skip_transaction_check = self.skip_transaction_check - self.skip_transaction_check = true + previous_skip_transaction_check = self.skip_transaction_check + Thread.current[:sidekiq_worker_skip_transaction_check] = true yield ensure - self.skip_transaction_check = skip_transaction_check + Thread.current[:sidekiq_worker_skip_transaction_check] = previous_skip_transaction_check + end + + def self.skip_transaction_check + Thread.current[:sidekiq_worker_skip_transaction_check] end module ClassMethods |