Fix interrupts during Ractor.select

Fixes [Bug #20168]
This commit is contained in:
Luke Gruber 2024-05-05 11:14:53 -04:00 committed by GitHub
parent 5398a46889
commit 6747fbe77d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 3 deletions

View File

@ -1466,6 +1466,25 @@ assert_equal '[:ok, :ok]', %q{
end
}
# Ractor.select is interruptible
assert_normal_exit %q{
trap(:INT) do
exit
end
r = Ractor.new do
loop do
sleep 1
end
end
Thread.new do
sleep 0.5
Process.kill(:INT, Process.pid)
end
Ractor.select(r)
}
# Ractor-local storage
assert_equal '[nil, "b", "a"]', %q{
ans = []

View File

@ -1804,17 +1804,17 @@ ractor_select_internal(rb_execution_context_t *ec, VALUE self, VALUE ractors, VA
int state;
EC_PUSH_TAG(ec);
if ((state = EC_EXEC_TAG() == TAG_NONE)) {
if ((state = EC_EXEC_TAG()) == TAG_NONE) {
result = ractor_selector__wait(selector, do_receive, do_yield, yield_value, move);
}
else {
EC_POP_TAG();
if (state != TAG_NONE) {
// ensure
ractor_selector_clear(selector);
// jump
EC_JUMP_TAG(ec, state);
}
EC_POP_TAG();
RB_GC_GUARD(ractors);
return result;