Skip to content

Commit

Permalink
Make Sentry.{close,get_main_hub} thread-safe (getsentry#2436)
Browse files Browse the repository at this point in the history
  • Loading branch information
solnic authored Oct 20, 2024
1 parent b4bbed2 commit 957c8d6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 7 additions & 3 deletions sentry-ruby/lib/sentry-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ module Sentry

THREAD_LOCAL = :sentry_hub

MUTEX = Mutex.new

class << self
# @!visibility private
def exception_locals_tp
Expand Down Expand Up @@ -275,8 +277,10 @@ def close

@background_worker.shutdown

@main_hub = nil
Thread.current.thread_variable_set(THREAD_LOCAL, nil)
MUTEX.synchronize do
@main_hub = nil
Thread.current.thread_variable_set(THREAD_LOCAL, nil)
end
end

# Returns true if the SDK is initialized.
Expand All @@ -303,7 +307,7 @@ def csp_report_uri
#
# @return [Hub]
def get_main_hub
@main_hub
MUTEX.synchronize { @main_hub }
end

# Takes an instance of Sentry::Breadcrumb and stores it to the current active scope.
Expand Down
3 changes: 0 additions & 3 deletions sentry-sidekiq/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ gem "sentry-rails", path: "../sentry-rails"
# loofah changed the required ruby version in a patch so we need to explicitly pin it
gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5

# For https://github.com/ruby/psych/issues/655
gem "psych", "5.1.0"

sidekiq_version = ENV["SIDEKIQ_VERSION"]
sidekiq_version = "7.0" if sidekiq_version.nil?
sidekiq_version = Gem::Version.new(sidekiq_version)
Expand Down

0 comments on commit 957c8d6

Please sign in to comment.