Skip to content

Commit d02cf27

Browse files
authored
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.
1 parent dd2d617 commit d02cf27

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

sentry-ruby/lib/sentry-ruby.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,8 @@ def init(&block)
233233
#
234234
# @return [void]
235235
def close
236-
@background_worker.perform { get_current_client&.transport&.flush }
237-
# session_flusher internally queues to the background worker too
238-
@session_flusher&.flush
239-
240-
@background_worker.shutdown
241-
242236
if @session_flusher
237+
@session_flusher.flush
243238
@session_flusher.kill
244239
@session_flusher = nil
245240
end
@@ -249,10 +244,16 @@ def close
249244
@backpressure_monitor = nil
250245
end
251246

252-
if configuration&.include_local_variables
253-
exception_locals_tp.disable
247+
if client = get_current_client
248+
client.transport.flush
249+
250+
if client.configuration.include_local_variables
251+
exception_locals_tp.disable
252+
end
254253
end
255254

255+
@background_worker.shutdown
256+
256257
@main_hub = nil
257258
Thread.current.thread_variable_set(THREAD_LOCAL, nil)
258259
end

0 commit comments

Comments
 (0)