Skip to content

Commit 94be884

Browse files
committed
Add mutex sync to SessionFlusher aggregates
1 parent a9b3687 commit 94be884

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

sentry-ruby/lib/sentry/session_flusher.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def initialize(configuration, client)
1010
@pending_aggregates = {}
1111
@release = configuration.release
1212
@environment = configuration.environment
13+
@mutex = Mutex.new
1314

1415
log_debug("[Sessions] Sessions won't be captured without a valid release") unless @release
1516
end
@@ -18,7 +19,6 @@ def flush
1819
return if @pending_aggregates.empty?
1920

2021
@client.capture_envelope(pending_envelope)
21-
@pending_aggregates = {}
2222
end
2323

2424
alias_method :run, :flush
@@ -42,11 +42,15 @@ def init_aggregates(aggregation_key)
4242
end
4343

4444
def pending_envelope
45-
envelope = Envelope.new
45+
aggregates = @mutex.synchronize do
46+
aggregates = @pending_aggregates.values
47+
@pending_aggregates = {}
48+
aggregates
49+
end
4650

51+
envelope = Envelope.new
4752
header = { type: "sessions" }
48-
payload = { attrs: attrs, aggregates: @pending_aggregates.values }
49-
53+
payload = { attrs: attrs, aggregates: aggregates }
5054
envelope.add_item(header, payload)
5155
envelope
5256
end

0 commit comments

Comments
 (0)