Skip to content

Commit

Permalink
Refactor Sentry.close (#2207)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
st0012 committed Dec 22, 2023
1 parent dd2d617 commit d02cf27
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions sentry-ruby/lib/sentry-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit d02cf27

Please sign in to comment.