tagomoris / right_speed

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ractor can't be killed by other Ractors

tagomoris opened this issue · comments

When a Ractor is doing I/O, it can'tf stop by itself (even when I/O is nonblock, IO.select will block).

r = Ractor.new(listen) { |listen|
  while connection = listen.accept
    # process
  end
}
Signal.trap(:INT) { r.kill }
# or r.stop, r.interrupt
# or r.raise(MyStopSignalError)

If a Ractor's input is Ractor.receive only, it can stop itself when it receives a stop signal (via Ractor.receive). But the Ractor is doing I/O, it can't listen Ractor.receive. So there are no any channels to tell it should stop.
Under the current situation, we can only stop the entire runtime at once without any shutdown processes.

So, I want a method to kill or interrupt the Ractor, or to raise an exception in that Ractor from the outside.

The alternative idea is:

  • Add a method/runtime-feature to select both I/O and Ractor (like golang's select)