Skip to content

Commit 67ea2d4

Browse files
committed
free terminated ThreadClients
fix #899
1 parent 7a37045 commit 67ea2d4

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/debug/session.rb

+12-1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ def initialize
128128
@obj_map = {} # { object_id => ... } for CDP
129129

130130
@tp_thread_begin = nil
131+
@tp_thread_end = nil
132+
131133
@commands = {}
132134
@unsafe_context = false
133135

@@ -169,8 +171,9 @@ def activate ui = nil, on_fork: false
169171
@ui = ui if ui
170172

171173
@tp_thread_begin&.disable
174+
@tp_thread_end&.disable
172175
@tp_thread_begin = nil
173-
176+
@tp_thread_end = nil
174177
@ui.activate self, on_fork: on_fork
175178

176179
q = Queue.new
@@ -192,6 +195,11 @@ def activate ui = nil, on_fork: false
192195
end
193196
@tp_thread_begin.enable
194197

198+
@tp_thread_end = TracePoint.new(:thread_end) do |tp|
199+
@th_clients.delete(Thread.current)
200+
end
201+
@tp_thread_end.enable
202+
195203
# session start
196204
q << true
197205
session_server_main
@@ -205,6 +213,7 @@ def deactivate
205213
@thread_stopper.disable
206214
@tp_load_script.disable
207215
@tp_thread_begin.disable
216+
@tp_thread_end.disable
208217
@bps.each_value{|bp| bp.disable}
209218
@th_clients.each_value{|thc| thc.close}
210219
@tracers.values.each{|t| t.disable}
@@ -219,11 +228,13 @@ def reset_ui ui
219228

220229
# activate new ui
221230
@tp_thread_begin.disable
231+
@tp_thread_end.disable
222232
@ui.activate self
223233
if @ui.respond_to?(:reader_thread) && thc = get_thread_client(@ui.reader_thread)
224234
thc.mark_as_management
225235
end
226236
@tp_thread_begin.enable
237+
@tp_thread_end.enable
227238
end
228239

229240
def pop_event

0 commit comments

Comments
 (0)