Project

General

Profile

Actions

Misc #21348

open

Should Tracepoint track retry as another "call" event?

Added by karthikc (Karthik Chandrasekariah) 3 days ago. Updated 1 day ago.

Status:
Open
Assignee:
-
[ruby-core:122175]

Description

When retry is executed in a method, Tracepoint records it as a new "call" event.

# tracepoint-retry.rb

# method that retries once
def foo
  attempts ||= 1
  raise "Fail" if attempts == 1
rescue
  attempts += 1
  retry
end

trace = TracePoint.new(:call, :return) do |tp|
  p [tp.event, tp.method_id]
end

trace.enable
foo
$ ruby -v
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [x86_64-darwin24]

$ ruby tracepoint-retry.rb
[:call, :foo]
[:call, :foo]
[:return, :foo]

It results in multiple "call" events and a single "return" event. Since the retry doesn't technically leave and re-enter the method, should we change Tracepoint to not fire the second "call" event?

Context - I am building a library that tracks everything that happened in a block of code. This behavior makes it look like foo was called within foo but the outer call never returned/completed.

Actions

Also available in: Atom PDF

Like0
Like0