Bug #20167
closedCode execution isn't recorded in Ractor
Description
reproduction code¶
# frozen-string-literal: true
require "coverage"
Coverage.start
require_relative "./some_lib"
# # some_lib.rb
# class C
# def hoge(i)
# i
# end
# end
r = Ractor.new do
loop do
v = Ractor.receive
ret_v = C.new.hoge(v)
Ractor.yield ret_v
end
end
2.times do |i|
r << i
r.take
end
Coverage.result.each do |file, lines|
if file.include?("some_ractor_lib")
if lines == [1, 1, 2, nil, nil]
puts "OK"
else
puts "expected: [1, 1, 2, nil, nil]"
puts "actual: #{lines.inspect}"
end
end
end
Target ruby version¶
3.2.0+ affected
Updated by mame (Yusuke Endoh) over 2 years ago
At this time, the coverage library should be able to only measure coverage for Ractor that invoked Coverage.start. (I have not tried but invoking Coverage.start in multiple Ractors may cause fatal problems.)
To improve this situation, probabily we need the following big modification.
Covearge.startregisters hooks to all existing Ractors.- The hook measures coverage data per Ractor, not globally.
Coverage.resultaggregates all coverage data from every Ractor.
Updated by jeremyevans0 (Jeremy Evans) over 2 years ago
- Is duplicate of Bug #20158: Ractor affects Coverage results added
Updated by jhawthorn (John Hawthorn) over 1 year ago
- Assignee set to ractor
Updated by hsbt (Hiroshi SHIBATA) over 1 year ago
- Status changed from Open to Assigned
Updated by ko1 (Koichi Sasada) 1 day ago
- Status changed from Assigned to Closed
Re-checked: this is fixed, and it was fixed as #19112.
I ran mame's rspec reproduction from #note-3 on four builds. The absolute event counts
differ between versions because they load different numbers of files; what matters is
the with/without-Ractor pair inside one version:
ruby TracePoint :line events no Ractor / with Ractor
3.3.2 22741 / 8112 <- reproduces, stops inside rubygems
3.4.4 35621 / 12738 <- reproduces
4.0.2 52294 / 52325 <- fine
master 4d185cce78 5432 / 5455 <- fine
GH-15468 (4fb537b1ee, "Make tracepoints with set_trace_func or TracePoint.new ractor
local", Fixes [Bug #19112]) is what fixed it: before that, GC'ing any Ractor object
cleared the global event flags and every enabled tracepoint with them, which is exactly
the "TracePoint stops firing part-way through" symptom here.
Closing as a duplicate of #19112.
Note that Coverage still does not record code executed inside a Ractor -- that is
#20167, which is a different cause (the coverage hook is registered on the Ractor that
called Coverage.start, and hook lists are per-Ractor) and stays open.