File tree Expand file tree Collapse file tree 3 files changed +54
-2
lines changed Expand file tree Collapse file tree 3 files changed +54
-2
lines changed Original file line number Diff line number Diff line change 40
40
- Respect `report_rescued_exceptions` config [#1847](https://github.com/getsentry/sentry-ruby/pull/1847)
41
41
- Fixes [#1840](https://github.com/getsentry/sentry-ruby/issues/1840)
42
42
- Rescue event' s to JSON conversion error [# 1853](https://github.com/getsentry/sentry-ruby/pull/1853)
43
+ - Rescue ` ThreadError` in ` SessionFlusher` and stop creating threads if flusher is killed [# 1851](https://github.com/getsentry/sentry-ruby/issues/1851)
44
+ - Fixes [# 1848](https://github.com/getsentry/sentry-ruby/issues/1848)
43
45
44
46
# ## Refactoring
45
47
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ class SessionFlusher
8
8
9
9
def initialize ( configuration , client )
10
10
@thread = nil
11
+ @exited = false
11
12
@client = client
12
13
@pending_aggregates = { }
13
14
@release = configuration . release
@@ -29,9 +30,16 @@ def flush
29
30
end
30
31
31
32
def add_session ( session )
33
+ return if @exited
32
34
return unless @release
33
35
34
- ensure_thread
36
+ begin
37
+ ensure_thread
38
+ rescue ThreadError
39
+ log_debug ( "Session flusher thread creation failed" )
40
+ @exited = true
41
+ return
42
+ end
35
43
36
44
return unless Session ::AGGREGATE_STATUSES . include? ( session . status )
37
45
@pending_aggregates [ session . aggregation_key ] ||= init_aggregates ( session . aggregation_key )
@@ -40,6 +48,8 @@ def add_session(session)
40
48
41
49
def kill
42
50
log_debug ( "Killing session flusher" )
51
+
52
+ @exited = true
43
53
@thread &.kill
44
54
end
45
55
Original file line number Diff line number Diff line change 126
126
expect ( pending_aggregates . keys . first ) . to be_a ( Time )
127
127
expect ( pending_aggregates . values . first ) . to include ( { errored : 0 , exited : 1 } )
128
128
end
129
+
130
+ context "when thread creation fails" do
131
+ before do
132
+ expect ( Thread ) . to receive ( :new ) . and_raise ( ThreadError )
133
+ end
134
+
135
+ it "doesn't create new thread" do
136
+ expect do
137
+ subject . add_session ( session )
138
+ end . to change { Thread . list . count } . by ( 0 )
139
+ end
140
+
141
+ it "noops" do
142
+ subject . add_session ( session )
143
+ expect ( subject . instance_variable_get ( :@pending_aggregates ) ) . to eq ( { } )
144
+ end
145
+
146
+ it "logs error" do
147
+ subject . add_session ( session )
148
+ expect ( string_io . string ) . to match ( /Session flusher thread creation failed/ )
149
+ end
150
+ end
151
+
152
+ context "when killed" do
153
+ before do
154
+ subject . kill
155
+ end
156
+
157
+ it "noops" do
158
+ subject . add_session ( session )
159
+ expect ( subject . instance_variable_get ( :@pending_aggregates ) ) . to eq ( { } )
160
+ end
161
+
162
+ it "doesn't create new thread" do
163
+ expect ( Thread ) . not_to receive ( :new )
164
+
165
+ expect do
166
+ subject . add_session ( session )
167
+ end . to change { Thread . list . count } . by ( 0 )
168
+ end
169
+ end
129
170
end
130
171
131
172
describe "#kill" do
132
173
it "logs message when killing the thread" do
133
174
subject . kill
134
-
135
175
expect ( string_io . string ) . to match ( /Killing session flusher/ )
136
176
end
137
177
end
You can’t perform that action at this time.
0 commit comments