Raise error on take/send for Ractors in child processes
Ractor objects that are available in a child process should raise a `Ractor::ClosedError` exception when called with `send` or `take` Co-authored-by: John Hawthorn <john@hawthorn.email>
This commit is contained in:
parent
f7ff380998
commit
e3452cfad2
Notes:
git
2025-05-08 17:53:41 +00:00
@ -2213,7 +2213,49 @@ assert_equal 'ok', %q{
|
||||
|
||||
# fork after creating Ractor
|
||||
assert_equal 'ok', %q{
|
||||
begin
|
||||
Ractor.new { Ractor.receive }
|
||||
_, status = Process.waitpid2 fork { }
|
||||
status.success? ? "ok" : status
|
||||
rescue NotImplementedError
|
||||
:ok
|
||||
end
|
||||
}
|
||||
|
||||
# Ractors should be terminated after fork
|
||||
assert_equal 'ok', %q{
|
||||
begin
|
||||
r = Ractor.new { Ractor.receive }
|
||||
_, status = Process.waitpid2 fork {
|
||||
begin
|
||||
r.take
|
||||
raise "ng"
|
||||
rescue Ractor::ClosedError
|
||||
end
|
||||
}
|
||||
r.send(123)
|
||||
raise unless r.take == 123
|
||||
status.success? ? "ok" : status
|
||||
rescue NotImplementedError
|
||||
:ok
|
||||
end
|
||||
}
|
||||
|
||||
# Ractors should be terminated after fork
|
||||
assert_equal 'ok', %q{
|
||||
begin
|
||||
r = Ractor.new { Ractor.receive }
|
||||
_, status = Process.waitpid2 fork {
|
||||
begin
|
||||
r.send(123)
|
||||
raise "ng"
|
||||
rescue Ractor::ClosedError
|
||||
end
|
||||
}
|
||||
r.send(123)
|
||||
raise unless r.take == 123
|
||||
status.success? ? "ok" : status
|
||||
rescue NotImplementedError
|
||||
:ok
|
||||
end
|
||||
}
|
||||
|
3
ractor.c
3
ractor.c
@ -2096,6 +2096,9 @@ rb_ractor_terminate_atfork(rb_vm_t *vm, rb_ractor_t *r)
|
||||
rb_gc_ractor_cache_free(r->newobj_cache);
|
||||
r->newobj_cache = NULL;
|
||||
r->status_ = ractor_terminated;
|
||||
r->sync.outgoing_port_closed = true;
|
||||
r->sync.incoming_port_closed = true;
|
||||
r->sync.will_basket.type.e = basket_type_none;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user