Fix 'require' from a ractor when the required file raises an error
If you catch an error that was raised from a file you required in a ractor, that error did not have its belonging reset from the main ractor to the current ractor, so you hit assertion errors in debug mode.
This commit is contained in:
parent
b7e751181e
commit
f64c89f18d
Notes:
git
2025-05-23 19:13:36 +00:00
3
ractor.c
3
ractor.c
@ -4217,9 +4217,12 @@ rb_ractor_require(VALUE feature)
|
||||
rb_ractor_channel_close(ec, crr.ch);
|
||||
|
||||
if (crr.exception != Qundef) {
|
||||
ractor_reset_belonging(crr.exception);
|
||||
rb_exc_raise(crr.exception);
|
||||
}
|
||||
else {
|
||||
RUBY_ASSERT(crr.result != Qundef);
|
||||
ractor_reset_belonging(crr.result);
|
||||
return crr.result;
|
||||
}
|
||||
}
|
||||
|
@ -79,6 +79,25 @@ class TestRactor < Test::Unit::TestCase
|
||||
end;
|
||||
end
|
||||
|
||||
def test_require_raises_and_no_ractor_belonging_issue
|
||||
assert_ractor(<<~'RUBY')
|
||||
require "tempfile"
|
||||
f = Tempfile.new(["file_to_require_from_ractor", ".rb"])
|
||||
f.write("raise 'uh oh'")
|
||||
f.flush
|
||||
err_msg = Ractor.new(f.path) do |path|
|
||||
begin
|
||||
require path
|
||||
rescue RuntimeError => e
|
||||
e.message # had confirm belonging issue here
|
||||
else
|
||||
nil
|
||||
end
|
||||
end.take
|
||||
assert_equal "uh oh", err_msg
|
||||
RUBY
|
||||
end
|
||||
|
||||
def assert_make_shareable(obj)
|
||||
refute Ractor.shareable?(obj), "object was already shareable"
|
||||
Ractor.make_shareable(obj)
|
||||
|
Loading…
x
Reference in New Issue
Block a user