Skip to content

Commit

Permalink
Make Sentry.{close,get_main_hub} thread-safe
Browse files Browse the repository at this point in the history
  • Loading branch information
solnic committed Oct 18, 2024
1 parent ee37a4a commit e4669f2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 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 @@ -226,6 +228,7 @@ def add_attachment(**opts)
# @yieldparam config [Configuration]
# @return [void]
def init(&block)
@mutex = MUTEX
config = Configuration.new
yield(config) if block_given?
config.detect_release
Expand Down Expand Up @@ -275,8 +278,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 +308,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

0 comments on commit e4669f2

Please sign in to comment.