diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2019-07-04 16:46:46 +0300 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2019-07-04 18:13:06 +0300 |
commit | 133b9f41088288a53d0b7cca0e9d5bab4a633567 (patch) | |
tree | 0c99a125bad52548aef570dbfbe2ade32283f59e /config | |
parent | b7ba5571128a59f12cbef40652717925ff779f4e (diff) |
Fix race in forbid_sidekiq_in_transactions.rb
Current code uses module attribute which stores value
global instead of locally (thread locally). This results
in concurrent accesses to overwrite the each other values
Diffstat (limited to 'config')
-rw-r--r-- | config/initializers/forbid_sidekiq_in_transactions.rb | 13 |
1 files changed, 7 insertions, 6 deletions
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 |