Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Sentry.{close,get_main_hub} thread-safe #2436

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
solnic marked this conversation as resolved.
Show resolved Hide resolved
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
Loading