Commit 133b9f41 authored by Kamil Trzciński's avatar Kamil Trzciński

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
parent b7ba5571
---
title: Fix race in forbid_sidekiq_in_transactions.rb
merge_request: 30359
author:
type: fixed
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment