From: eregontp@... Date: 2021-03-31T18:34:47+00:00 Subject: [ruby-core:103130] [Ruby master Feature#17363] Timeouts Issue #17363 has been updated by Eregon (Benoit Daloze). Timeout.wake sounds a bit like Java's Thread#interrupt(), correct? So it would interrupt blocking calls (`File.read`/`Queue#pop`/`rb_thread_call_without_gvl`/`sleep`/`Mutex#lock`/etc) but wouldn't interrupt not-blocking Ruby code like `loop{1+1}` or `while true; 1+1; end`. Also if it happens while the Thread is not doing a blocking call it should probably set a flag that's then checked before any of these blocking calls (like `Java's Thread#interrupt()`), otherwise it would be too easy to lose such an interrupt/timeout. I'm not entirely sure how it would work to check the flag just before the blocking call and making sure to not lose an interrupt sent in between, but it should be possible. Related discussion: https://twitter.com/schneems/status/1377309342819512320 and https://www.schneems.com/2017/02/21/the-oldest-bug-in-ruby-why-racktimeout-might-hose-your-server/ ---------------------------------------- Feature #17363: Timeouts https://bugs.ruby-lang.org/issues/17363#change-91203 * Author: marcandre (Marc-Andre Lafortune) * Status: Assigned * Priority: Normal * Assignee: ko1 (Koichi Sasada) ---------------------------------------- Builtin methods like `Queue.pop` and `Ractor.receive` have no timeout parameter. We should either: - provide such a parameter - and/or provide a `Timeout::wake` that raises an timeout error only if the block is currently sleeping. Details: ```ruby q = Queue.new # ... elem = Timeout::timeout(42) { q.pop } # => It is possible that an element is retreived from the queue but never stored in `elem` elem = Timeout::wake(42) { q.pop } # => Guaranteed that either element is retrieved from the queue or an exception is raised, never both Timeout::wake(42) { loop {} } # => infinite loop # and/or elem = q.pop(timeout: 42) ``` Currently, the only reliable way to have a Queue that accepts a timeout is to re-implement it from scratch. This post describe how involved that can be: https://spin.atomicobject.com/2017/06/28/queue-pop-with-timeout-fixed/ -- https://bugs.ruby-lang.org/ Unsubscribe: