[#105450] [Ruby master Feature#18228] Add a `timeout` option to `IO.copy_stream` — "byroot (Jean Boussier)" <noreply@...>
SXNzdWUgIzE4MjI4IGhhcyBiZWVuIHJlcG9ydGVkIGJ5IGJ5cm9vdCAoSmVhbiBCb3Vzc2llciku
11 messages
2021/09/27
[ruby-core:105287] [Ruby master Bug#17568] Thread.handle_interrupt is per-Thread but should probably be per-Fiber
From:
"ko1 (Koichi Sasada)" <noreply@...>
Date:
2021-09-16 07:12:51 UTC
List:
ruby-core #105287
Issue #17568 has been updated by ko1 (Koichi Sasada).
I understand some case it is confusing, but if Fiber is used to represent the data structure like Enumerator, Thread-wide mask is needed.
Could you give us the example which should be fiber local?
mame-san also proposed `Fiber.handle_interrupt` for fiber local handler to set fiber local setting.
----------------------------------------
Bug #17568: Thread.handle_interrupt is per-Thread but should probably be per-Fiber
https://bugs.ruby-lang.org/issues/17568#change-93697
* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
`Thread.handle_interrupt` and the pending interrupts is currently kept as state on the thread (`rb_thread_t`).
However, that seems potentially confusing when `Fiber`s are used.
For instance, this innocent-looking `Fiber` will forever disable interrupts in the main thread:
```ruby
main_thread = Thread.current
never_die = Fiber.new do
Thread.handle_interrupt(RuntimeError => :never) do
Fiber.yield
end
end
begin
Thread.new { main_thread.raise "interrupt1" }.join
rescue => e
puts "raised: #{e}"
end
never_die.resume
Thread.new { main_thread.raise "interrupt2" }.join
Thread.new { main_thread.raise "interrupt3" }.join
p :after
```
Output is:
```
raised: interrupt1
:after
```
(I noticed these weird semantics when implementing `Thread.handle_interrupt` on TruffleRuby, and got a fairly subtle bug due to multiple `Fiber`s of the same `Thread` queuing the same interrupt multiple times in the `Thread`'s interrupt queue).
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>