summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2019-07-04 15:46:46 +0200
committerKamil Trzciński <ayufan@ayufan.eu>2019-07-04 17:13:06 +0200
commit133b9f41088288a53d0b7cca0e9d5bab4a633567 (patch)
tree0c99a125bad52548aef570dbfbe2ade32283f59e
parentb7ba5571128a59f12cbef40652717925ff779f4e (diff)
downloadgitlab-ce-133b9f41088288a53d0b7cca0e9d5bab4a633567.tar.gz
Fix race in forbid_sidekiq_in_transactions.rbfix-sidekiq-transaction-check-race
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
-rw-r--r--changelogs/unreleased/fix-sidekiq-transaction-check-race.yml5
-rw-r--r--config/initializers/forbid_sidekiq_in_transactions.rb13
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