Actions
Bug #20089
openFiber#kill transfers to root fiber
Description
I was hoping to use Fiber#kill
to clean up formerly .transfer
-d Fibers and work around https://bugs.ruby-lang.org/issues/20081, but I found that Fiber#kill
has a similar control flow jump behavior. Is this on purpose, or a bug?
Here's a script to test the behavior:
manager = Fiber.new do
worker = Fiber.new do
puts "2. Begin Worker"
manager.transfer
puts "This should never print -- killed"
end
puts "1. Transfer to Worker"
worker.transfer
puts "3. Killing Worker"
worker.kill
puts "4. Finished manager"
end
manager.transfer
puts "5. Finished script"
I expected items 1
through 5
to be printed in order, but in fact, 4
is never printed:
$ ruby fiber_transfer_test.rb
1. Transfer to Worker
2. Begin Worker
3. Killing Worker
5. Finished script
It seems like worker.kill
is transferring control to the top-level fiber instead of giving it back to manager
.
I also tried having the thread kill itself, hoping it would return to the fiber that originally .transfer
ed to it, but it also seems to jump out:
manager = Fiber.new do
worker = Fiber.new do
puts "2. Begin Worker"
manager.transfer
Fiber.current.kill
puts "This should never print -- killed"
end
puts "1. Transfer to Worker"
worker.transfer
puts "3. Killing Worker"
worker.transfer
puts "4. Finished manager"
end
manager.transfer
puts "5. Finished script"
Prints:
1. Transfer to Worker
2. Begin Worker
3. Killing Worker
5. Finished script
Actions
Like1
Like0Like0Like0Like0Like0Like0Like0