Skip to content

Commit 957c8d6

Browse files
authored
Make Sentry.{close,get_main_hub} thread-safe (#2436)
1 parent b4bbed2 commit 957c8d6

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

sentry-ruby/lib/sentry-ruby.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ module Sentry
5050

5151
THREAD_LOCAL = :sentry_hub
5252

53+
MUTEX = Mutex.new
54+
5355
class << self
5456
# @!visibility private
5557
def exception_locals_tp
@@ -275,8 +277,10 @@ def close
275277

276278
@background_worker.shutdown
277279

278-
@main_hub = nil
279-
Thread.current.thread_variable_set(THREAD_LOCAL, nil)
280+
MUTEX.synchronize do
281+
@main_hub = nil
282+
Thread.current.thread_variable_set(THREAD_LOCAL, nil)
283+
end
280284
end
281285

282286
# Returns true if the SDK is initialized.
@@ -303,7 +307,7 @@ def csp_report_uri
303307
#
304308
# @return [Hub]
305309
def get_main_hub
306-
@main_hub
310+
MUTEX.synchronize { @main_hub }
307311
end
308312

309313
# Takes an instance of Sentry::Breadcrumb and stores it to the current active scope.

sentry-sidekiq/Gemfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ gem "sentry-rails", path: "../sentry-rails"
1212
# loofah changed the required ruby version in a patch so we need to explicitly pin it
1313
gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5
1414

15-
# For https://github.com/ruby/psych/issues/655
16-
gem "psych", "5.1.0"
17-
1815
sidekiq_version = ENV["SIDEKIQ_VERSION"]
1916
sidekiq_version = "7.0" if sidekiq_version.nil?
2017
sidekiq_version = Gem::Version.new(sidekiq_version)

0 commit comments

Comments
 (0)