Skip to content

Commit 1a32a15

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

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
- Fix `send_default_pii` handling in rails controller spans [#2443](https://github.com/getsentry/sentry-ruby/pull/2443)
1818
- Fixes [#2438](https://github.com/getsentry/sentry-ruby/issues/2438)
1919
- Fix `RescuedExceptionInterceptor` to handle an empty configuration [#2428](https://github.com/getsentry/sentry-ruby/pull/2428)
20+
- Add mutex sync to `SessionFlusher` aggregates [#2469](https://github.com/getsentry/sentry-ruby/pull/2469)
21+
- Fixes [#2468](https://github.com/getsentry/sentry-ruby/issues/2468)
2022

2123
## 5.21.0
2224

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)