Skip to content

Tracing :call doesn't work if the traced code is running on a different thread #8697

@mauricioszabo

Description

@mauricioszabo

Environment Information

  • JRuby version: jruby 10.0.0.0-SNAPSHOT (3.4.2) 2025-03-13 a4e4d7d OpenJDK 64-Bit Server VM 21.0.6+7-Ubuntu-124.04.1 on 21.0.6+7-Ubuntu-124.04.1 +indy +jit [x86_64-linux]
  • Operating system and platform: Ubuntu 24.04 / 6.8.0-1010-nvidia Become java statics #10-Ubuntu SMP PREEMPT_DYNAMIC Mon Jul 15 15:04:16 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Expected Behavior

TracePoint should work if we start a new thread. The following code shows the issue:

trace = TracePoint.new(:call) do |tp|
  puts "Tracing: #{tp.path}:#{tp.lineno}"
end
trace.enable

def something(a, b)
  result = yield a, b
  "Result: #{result}"
end

def make_sum(a, b)
  a + b
end

puts "Without a thread:"
something(10, 20) do |a, b|
  make_sum(a, b)
end

puts "\nWith a thread:"
something(10, 20) do |a, b|
  Thread.new do
    make_sum(a, b)
  end.join
end

On MRI, this prints:

Without a thread:
Tracing: /tmp/trace_example.rb:6
Tracing: /tmp/trace_example.rb:11

With a thread:
Tracing: /tmp/trace_example.rb:6
Tracing: /tmp/trace_example.rb:11

But on JRuby, this prints:

Without a thread:
Tracing: /tmp/trace_example.rb:6
Tracing: /tmp/trace_example.rb:11

With a thread:
Tracing: /tmp/trace_example.rb:6

Exporting JRUBY_OPTS='--debug' doesn't change the output

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions