summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Gruber <luke.gru@gmail.com>2024-05-05 11:14:53 -0400
committerGitHub <noreply@github.com>2024-05-05 15:14:53 +0000
commit6747fbe77dcac26a457bb1386f55f3c27321040a (patch)
tree47cc7e025b25e12cb910c6aa5c0ac4da7a4a0737
parent5398a46889fc98c734c00d8d71439b1ffc2912c1 (diff)
Fix interrupts during Ractor.select
Fixes [Bug #20168]
-rw-r--r--bootstraptest/test_ractor.rb19
-rw-r--r--ractor.c6
2 files changed, 22 insertions, 3 deletions
diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb
index 451b58e793..0390d38f9c 100644
--- a/bootstraptest/test_ractor.rb
+++ b/bootstraptest/test_ractor.rb
@@ -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 = []
diff --git a/ractor.c b/ractor.c
index f6b2b22c9a..231a83db6f 100644
--- a/ractor.c
+++ b/ractor.c
@@ -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;