ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "rmosolgo (Robert Mosolgo) via ruby-core" <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: "rmosolgo (Robert Mosolgo)" <noreply@ruby-lang.org>
Subject: [ruby-core:115911] [Ruby master Bug#20089] Fiber#kill transfers to root fiber
Date: Tue, 26 Dec 2023 16:46:04 +0000 (UTC)	[thread overview]
Message-ID: <redmine.issue-20089.20231226164604.8779@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-20089.20231226164604.8779@ruby-lang.org

Issue #20089 has been reported by rmosolgo (Robert Mosolgo).

----------------------------------------
Bug #20089: Fiber#kill transfers to root fiber
https://bugs.ruby-lang.org/issues/20089

* Author: rmosolgo (Robert Mosolgo)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22]
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
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: 

```ruby
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: 

```ruby
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
```



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

       reply	other threads:[~2023-12-26 16:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-26 16:46 rmosolgo (Robert Mosolgo) via ruby-core [this message]
2023-12-27 21:53 ` [ruby-core:115942] [Ruby master Bug#20089] Fiber#kill transfers to root fiber ioquatix (Samuel Williams) via ruby-core
2023-12-28 15:57 ` [ruby-core:115966] " rmosolgo (Robert Mosolgo) via ruby-core
2024-04-07 14:39 ` [ruby-core:117462] " ioquatix (Samuel Williams) via ruby-core
2024-04-07 14:39 ` [ruby-core:117463] " ioquatix (Samuel Williams) via ruby-core
2024-04-17 12:21 ` [ruby-core:117565] " ioquatix (Samuel Williams) via ruby-core

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.issue-20089.20231226164604.8779@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    --cc=noreply@ruby-lang.org \
    --cc=ruby-core@ml.ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).