From d02cf27934e7819602460485db7ae326a8a157d1 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Fri, 22 Dec 2023 13:22:01 +0000 Subject: [PATCH] Refactor Sentry.close (#2207) When reviewing #2206, I spotted 2 things that could be improved: - When closing the SDK, we shouldn't need to enqueue the last client report sending to background worker again. This makes the behaviour of `close` more difficult to predict. - Since the session flusher can still enqueue a job to background worker when flushing, we should postpone background worker's shutdown instead. --- sentry-ruby/lib/sentry-ruby.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/sentry-ruby/lib/sentry-ruby.rb b/sentry-ruby/lib/sentry-ruby.rb index 900172f48..c2f20b487 100644 --- a/sentry-ruby/lib/sentry-ruby.rb +++ b/sentry-ruby/lib/sentry-ruby.rb @@ -233,13 +233,8 @@ def init(&block) # # @return [void] def close - @background_worker.perform { get_current_client&.transport&.flush } - # session_flusher internally queues to the background worker too - @session_flusher&.flush - - @background_worker.shutdown - if @session_flusher + @session_flusher.flush @session_flusher.kill @session_flusher = nil end @@ -249,10 +244,16 @@ def close @backpressure_monitor = nil end - if configuration&.include_local_variables - exception_locals_tp.disable + if client = get_current_client + client.transport.flush + + if client.configuration.include_local_variables + exception_locals_tp.disable + end end + @background_worker.shutdown + @main_hub = nil Thread.current.thread_variable_set(THREAD_LOCAL, nil) end