@@ -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
@@ -248,35 +251,37 @@ def init(&block)
248251 #
249252 # @return [void]
250253 def close
251- if @session_flusher
252- @session_flusher . flush
253- @session_flusher . kill
254- @session_flusher = nil
255- end
254+ @mutex . synchronize do
255+ if @session_flusher
256+ @session_flusher . flush
257+ @session_flusher . kill
258+ @session_flusher = nil
259+ end
256260
257- if @backpressure_monitor
258- @backpressure_monitor . kill
259- @backpressure_monitor = nil
260- end
261+ if @backpressure_monitor
262+ @backpressure_monitor . kill
263+ @backpressure_monitor = nil
264+ end
261265
262- if @metrics_aggregator
263- @metrics_aggregator . flush ( force : true )
264- @metrics_aggregator . kill
265- @metrics_aggregator = nil
266- end
266+ if @metrics_aggregator
267+ @metrics_aggregator . flush ( force : true )
268+ @metrics_aggregator . kill
269+ @metrics_aggregator = nil
270+ end
267271
268- if client = get_current_client
269- client . flush
272+ if client = get_current_client
273+ client . flush
270274
271- if client . configuration . include_local_variables
272- exception_locals_tp . disable
275+ if client . configuration . include_local_variables
276+ exception_locals_tp . disable
277+ end
273278 end
274- end
275279
276- @background_worker . shutdown
280+ @background_worker . shutdown
277281
278- @main_hub = nil
279- Thread . current . thread_variable_set ( THREAD_LOCAL , nil )
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.
0 commit comments