Skip to content

Commit e4669f2

Browse files
committed
Make Sentry.{close,get_main_hub} thread-safe
1 parent ee37a4a commit e4669f2

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

sentry-ruby/lib/sentry-ruby.rb

Lines changed: 8 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
@@ -226,6 +228,7 @@ def add_attachment(**opts)
226228
# @yieldparam config [Configuration]
227229
# @return [void]
228230
def init(&block)
231+
@mutex = MUTEX
229232
config = Configuration.new
230233
yield(config) if block_given?
231234
config.detect_release
@@ -275,8 +278,10 @@ def close
275278

276279
@background_worker.shutdown
277280

278-
@main_hub = nil
279-
Thread.current.thread_variable_set(THREAD_LOCAL, nil)
281+
MUTEX.synchronize do
282+
@main_hub = nil
283+
Thread.current.thread_variable_set(THREAD_LOCAL, nil)
284+
end
280285
end
281286

282287
# Returns true if the SDK is initialized.
@@ -303,7 +308,7 @@ def csp_report_uri
303308
#
304309
# @return [Hub]
305310
def get_main_hub
306-
@main_hub
311+
MUTEX.synchronize { @main_hub }
307312
end
308313

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

0 commit comments

Comments
 (0)