ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: eregontp@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:103130] [Ruby master Feature#17363] Timeouts
Date: Wed, 31 Mar 2021 18:34:47 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-91203.20210331183446.182@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-17363.20201203145816.182@ruby-lang.org

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/

  parent reply	other threads:[~2021-03-31 18:35 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-03 14:58 [ruby-core:101217] [Ruby master Feature#17363] Timeouts marcandre-ruby-core
2020-12-03 15:11 ` [ruby-core:101220] " merch-redmine
2020-12-03 19:04 ` [ruby-core:101224] " eregontp
2020-12-04  3:20 ` [ruby-core:101236] " nobu
2020-12-10  8:19 ` [ruby-core:101367] " ko1
2020-12-10  8:20 ` [ruby-core:101368] " ko1
2020-12-10 10:37 ` [ruby-core:101378] " marcandre-ruby-core
2020-12-10 11:45 ` [ruby-core:101383] " eregontp
2020-12-10 11:48 ` [ruby-core:101384] " marcandre-ruby-core
2020-12-10 11:53 ` [ruby-core:101386] " eregontp
2020-12-11  5:48 ` [ruby-core:101415] " marcandre-ruby-core
2020-12-11 10:35 ` [ruby-core:101416] " nobu
2020-12-13 12:29 ` [ruby-core:101436] " eregontp
2020-12-13 12:30 ` [ruby-core:101437] " eregontp
2021-01-12  7:31 ` [ruby-core:102024] " ko1
2021-02-11 23:30 ` [ruby-core:102465] " samuel
2021-02-16 13:25 ` [ruby-core:102538] " naruse
2021-03-31 18:34 ` eregontp [this message]
2022-05-14  9:06 ` [ruby-core:108551] " Eregon (Benoit Daloze)

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.journal-91203.20210331183446.182@ruby-lang.org \
    --to=ruby-core@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).