File tree Expand file tree Collapse file tree 2 files changed +19
-10
lines changed
gems/codetracer-pure-ruby-recorder/lib Expand file tree Collapse file tree 2 files changed +19
-10
lines changed Original file line number Diff line number Diff line change 1- No insights yet. Please add content here and remove this line.
1+ When tracing scripts with the pure Ruby recorder, avoid including the
2+ `RubyRecorder` instance (or its `TraceRecord`) among the inspected local
3+ variables. Otherwise the serializer will descend into the tracer's own
4+ state which quickly explodes in size and appears as infinite recursion.
5+ `load_variables` filters these objects out.
Original file line number Diff line number Diff line change @@ -215,16 +215,21 @@ def deactivate
215215
216216 private
217217
218+ # Collect local variables from the current +binding+. Variables that refer to
219+ # the tracer itself or the trace record are ignored to avoid recursively
220+ # serialising the internal state of the tracer.
218221 def load_variables ( binding )
219- if !binding . nil?
220- # $stdout.write binding.local_variables
221- binding . local_variables . map do |name |
222- v = binding . local_variable_get ( name )
223- out = to_value ( v )
224- [ name , out ]
225- end
226- else
227- [ ]
222+ return [ ] if binding . nil?
223+
224+ binding . local_variables . filter_map do |name |
225+ v = binding . local_variable_get ( name )
226+
227+ next if v . equal? ( self ) || v . equal? ( @record )
228+ next if defined? ( RubyRecorder ) && v . is_a? ( RubyRecorder )
229+ next if defined? ( TraceRecord ) && v . is_a? ( TraceRecord )
230+
231+ out = to_value ( v )
232+ [ name , out ]
228233 end
229234 end
230235end
You can’t perform that action at this time.
0 commit comments