ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:115881] [Ruby master Bug#20082] Killing fibers across threads: unexpected exception
@ 2023-12-23 21:15 zverok (Victor Shepelev) via ruby-core
  2023-12-23 21:40 ` [ruby-core:115882] " zverok (Victor Shepelev) via ruby-core
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: zverok (Victor Shepelev) via ruby-core @ 2023-12-23 21:15 UTC (permalink / raw)
  To: ruby-core; +Cc: zverok (Victor Shepelev)

Issue #20082 has been reported by zverok (Victor Shepelev).

----------------------------------------
Bug #20082: Killing fibers across threads: unexpected exception
https://bugs.ruby-lang.org/issues/20082

* Author: zverok (Victor Shepelev)
* Status: Open
* Priority: Normal
* Assignee: ioquatix (Samuel Williams)
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
For providing the example in a changelog, I tried to imitate killing fibers belonging to other threads.
Documentation [claims](https://docs.ruby-lang.org/en/master/Fiber.html#method-i-kill)

> Raises FiberError if called on a fiber belonging to another thread.

So, I created this artificial example to check how it works:
```ruby
fibers = []

Thread.new {
  f = Fiber.new { (1..).each { sleep(0.1) } }
  fibers << f
  f.resume
}
sleep(0.1) # to make sure the thread has started

fibers.last.kill
```
The example indeed fails with `FiberError`, but the error message is confusing:
```
in `kill': attempt to resume a resumed fiber (double resume) (FiberError)
```

Is this an expected message for such case? Or am I misunderstanding something?



-- 
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/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:115882] [Ruby master Bug#20082] Killing fibers across threads: unexpected exception
  2023-12-23 21:15 [ruby-core:115881] [Ruby master Bug#20082] Killing fibers across threads: unexpected exception zverok (Victor Shepelev) via ruby-core
@ 2023-12-23 21:40 ` zverok (Victor Shepelev) via ruby-core
  2023-12-24  0:36 ` [ruby-core:115883] " rubyFeedback (robert heiler) via ruby-core
  2023-12-26 11:34 ` [ruby-core:115903] " ioquatix (Samuel Williams) via ruby-core
  2 siblings, 0 replies; 4+ messages in thread
From: zverok (Victor Shepelev) via ruby-core @ 2023-12-23 21:40 UTC (permalink / raw)
  To: ruby-core; +Cc: zverok (Victor Shepelev)

Issue #20082 has been updated by zverok (Victor Shepelev).


UPD: OTOH, without resuming, the code doesn't see any problem at all (despite the claim about killing other thread's fibers):
```ruby
fibers = []

Thread.new {
  f = Fiber.new { (1..).each { sleep(0.1) } }
  fibers << f
}
sleep(0.1) # to make sure the thread have started

p fibers.last.kill
#=> #<Fiber:0x00007f73f682c078 examples/fiber_kill.rb:7 (terminated)>
```

----------------------------------------
Bug #20082: Killing fibers across threads: unexpected exception
https://bugs.ruby-lang.org/issues/20082#change-105839

* Author: zverok (Victor Shepelev)
* Status: Open
* Priority: Normal
* Assignee: ioquatix (Samuel Williams)
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
For providing the example in a changelog, I tried to imitate killing fibers belonging to other threads.
Documentation [claims](https://docs.ruby-lang.org/en/master/Fiber.html#method-i-kill)

> Raises FiberError if called on a fiber belonging to another thread.

So, I created this artificial example to check how it works:
```ruby
fibers = []

Thread.new {
  f = Fiber.new { (1..).each { sleep(0.1) } }
  fibers << f
  f.resume
}
sleep(0.1) # to make sure the thread has started

fibers.last.kill
```
The example indeed fails with `FiberError`, but the error message is confusing:
```
in `kill': attempt to resume a resumed fiber (double resume) (FiberError)
```

Is this an expected message for such case? Or am I misunderstanding something?



-- 
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/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:115883] [Ruby master Bug#20082] Killing fibers across threads: unexpected exception
  2023-12-23 21:15 [ruby-core:115881] [Ruby master Bug#20082] Killing fibers across threads: unexpected exception zverok (Victor Shepelev) via ruby-core
  2023-12-23 21:40 ` [ruby-core:115882] " zverok (Victor Shepelev) via ruby-core
@ 2023-12-24  0:36 ` rubyFeedback (robert heiler) via ruby-core
  2023-12-26 11:34 ` [ruby-core:115903] " ioquatix (Samuel Williams) via ruby-core
  2 siblings, 0 replies; 4+ messages in thread
From: rubyFeedback (robert heiler) via ruby-core @ 2023-12-24  0:36 UTC (permalink / raw)
  To: ruby-core; +Cc: rubyFeedback (robert heiler)

Issue #20082 has been updated by rubyFeedback (robert heiler).


The error message is indeed somewhat peculiar:

"attempt to resume **a resumed fiber** ( **double resume** )"

I am not sure what "double resume" means here. But, even aside
from this, I could not even try to want to explain what "to
resume a resumed fiber" really means. Perhaps something else
was meant here? Or it was meant to convey that the code tried
to resume an already-resumed fiber. Either way it is indeed
peculiar.

I'd even be radical and suggest to get rid of fibers and instead
put everything under Thread, but I guess that is not possible
for various reasons. To me Threads seem easier to understand 
than Fibers though.

----------------------------------------
Bug #20082: Killing fibers across threads: unexpected exception
https://bugs.ruby-lang.org/issues/20082#change-105840

* Author: zverok (Victor Shepelev)
* Status: Open
* Priority: Normal
* Assignee: ioquatix (Samuel Williams)
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
For providing the example in a changelog, I tried to imitate killing fibers belonging to other threads.
Documentation [claims](https://docs.ruby-lang.org/en/master/Fiber.html#method-i-kill)

> Raises FiberError if called on a fiber belonging to another thread.

So, I created this artificial example to check how it works:
```ruby
fibers = []

Thread.new {
  f = Fiber.new { (1..).each { sleep(0.1) } }
  fibers << f
  f.resume
}
sleep(0.1) # to make sure the thread has started

fibers.last.kill
```
The example indeed fails with `FiberError`, but the error message is confusing:
```
in `kill': attempt to resume a resumed fiber (double resume) (FiberError)
```

Is this an expected message for such case? Or am I misunderstanding something?



-- 
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/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:115903] [Ruby master Bug#20082] Killing fibers across threads: unexpected exception
  2023-12-23 21:15 [ruby-core:115881] [Ruby master Bug#20082] Killing fibers across threads: unexpected exception zverok (Victor Shepelev) via ruby-core
  2023-12-23 21:40 ` [ruby-core:115882] " zverok (Victor Shepelev) via ruby-core
  2023-12-24  0:36 ` [ruby-core:115883] " rubyFeedback (robert heiler) via ruby-core
@ 2023-12-26 11:34 ` ioquatix (Samuel Williams) via ruby-core
  2 siblings, 0 replies; 4+ messages in thread
From: ioquatix (Samuel Williams) via ruby-core @ 2023-12-26 11:34 UTC (permalink / raw)
  To: ruby-core; +Cc: ioquatix (Samuel Williams)

Issue #20082 has been updated by ioquatix (Samuel Williams).


> Raises FiberError if called on a fiber belonging to another thread.

I agree the error is a little confusing, but the reality is it's probably okay.

"in `kill': attempt to resume a resumed fiber (double resume) (FiberError)"

You are literally reaching across into a fiber which is currently resumed and executing sleep. This is a text book definition of a double resume.

To get the error message I imagine you are after:

```ruby
fibers = []

Thread.new {
  f = Fiber.new { Fiber.yield }
  f.resume
  fibers << f
}.join

fibers.last.kill
```

> without resuming, the code doesn't see any problem at all (despite the claim about killing other thread's fibers):

A fiber is lazily constructed according to the first thread it is resumed on. So, this behaviour looks okay to me.

----------------------------------------
Bug #20082: Killing fibers across threads: unexpected exception
https://bugs.ruby-lang.org/issues/20082#change-105858

* Author: zverok (Victor Shepelev)
* Status: Open
* Priority: Normal
* Assignee: ioquatix (Samuel Williams)
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
For providing the example in a changelog, I tried to imitate killing fibers belonging to other threads.
Documentation [claims](https://docs.ruby-lang.org/en/master/Fiber.html#method-i-kill)

> Raises FiberError if called on a fiber belonging to another thread.

So, I created this artificial example to check how it works:
```ruby
fibers = []

Thread.new {
  f = Fiber.new { (1..).each { sleep(0.1) } }
  fibers << f
  f.resume
}
sleep(0.1) # to make sure the thread has started

fibers.last.kill
```
The example indeed fails with `FiberError`, but the error message is confusing:
```
in `kill': attempt to resume a resumed fiber (double resume) (FiberError)
```

Is this an expected message for such case? Or am I misunderstanding something?



-- 
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/

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-12-26 11:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-23 21:15 [ruby-core:115881] [Ruby master Bug#20082] Killing fibers across threads: unexpected exception zverok (Victor Shepelev) via ruby-core
2023-12-23 21:40 ` [ruby-core:115882] " zverok (Victor Shepelev) via ruby-core
2023-12-24  0:36 ` [ruby-core:115883] " rubyFeedback (robert heiler) via ruby-core
2023-12-26 11:34 ` [ruby-core:115903] " ioquatix (Samuel Williams) via ruby-core

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 NNTP newsgroup(s).