115 Commits
Author SHA1 Message Date
Samuel Williams 77ef74d3c7 [ruby/timeout] Bump version to 0.6.1
https://github.com/ruby/timeout/commit/951e8025ec
2026-03-09 22:04:19 +00:00
Samuel Williams f315d250b4 [ruby/timeout] Compatibility with Fiber scheduler.
(https://github.com/ruby/timeout/pull/97)

[Bug #21947]

https://github.com/ruby/timeout/commit/55d7c84b50
2026-03-09 03:48:20 +00:00
Nobuyoshi Nakada 184d4be893 [ruby/timeout] [DOC] document the private instance method
https://github.com/ruby/timeout/commit/52e85fed75
2026-02-03 03:44:27 +00:00
Masafumi Koba 81e06e7004 [ruby/timeout] Improve Timeout.timeout documentation formatting and typos
This commit makes a few minor improvements to the documentation of the `Timeout.timeout` method.
The changes include fixing typos and enhancing formatting for better readability.

We can see the latest version of the documentation here:
https://docs.ruby-lang.org/en/master/Timeout.html#method-c-timeout

Also, we can verify this change locally by running:

```shell
rdoc
open doc/Timeout.html
```

https://github.com/ruby/timeout/commit/53ee559e15
2026-01-17 14:05:07 +00:00
Hiroshi SHIBATA 8e25812194 [ruby/timeout] v0.6.0
https://github.com/ruby/timeout/commit/ab79dfff47
2025-12-17 15:47:43 +09:00
Benoit Daloze b49ff7cc70 [ruby/timeout] Make Timeout.timeout work in a trap handler on CRuby
* Fixes https://github.com/ruby/timeout/issues/17

https://github.com/ruby/timeout/commit/1a499a8f96
2025-12-11 13:38:35 +00:00
Benoit Daloze 9865048a34 [ruby/timeout] Encapsulate adding a timeout Request
https://github.com/ruby/timeout/commit/cb2ba88fed
2025-12-11 13:38:35 +00:00
Benoit Daloze c678e1bdd3 [ruby/timeout] Revise Timeout.timeout docs and add a section about ensure
https://github.com/ruby/timeout/commit/7cfa5a6778
2025-12-11 13:05:40 +00:00
Benoit Daloze 46d8e6d993 [ruby/timeout] Reset the interrupt mask when creating the Timeout thread
* Add tests related to Thread.handle_interrupt
* Fixes https://github.com/ruby/timeout/issues/41

https://github.com/ruby/timeout/commit/a52720e82a
2025-12-11 13:05:39 +00:00
Hiroshi SHIBATA 4655b174d5 [ruby/timeout] v0.5.0
https://github.com/ruby/timeout/commit/837d5aac73
2025-12-08 03:06:40 +00:00
Benoit Daloze 00b91c727f [ruby/timeout] Simplify logic to make GET_TIME shareable
https://github.com/ruby/timeout/commit/281b2507e7
2025-12-05 18:32:14 +00:00
Benoit Daloze 3e189ddb9d [ruby/timeout] Fix logic for Ractor support
* Fix indentation to stay a multiple of 2 spaces.

https://github.com/ruby/timeout/commit/a1d784cb66
2025-12-05 18:32:13 +00:00
Benoit Daloze dc406af9cb [ruby/timeout] Fix condition and fix test to catch that broken condition
https://github.com/ruby/timeout/commit/82fb6f6925
2025-12-05 18:32:13 +00:00
Benoit Daloze a523e9d872 [ruby/timeout] Minor tweaks
https://github.com/ruby/timeout/commit/daab9a2193
2025-12-05 18:32:13 +00:00
Koichi Sasada ec28bd75a8 [ruby/timeout] support Ractor
1. Introduce State to store all status.
2. Store State instance to the Ractor local storage if possible
3. Make `GET_TIME` (Method object) shareable if possible

3 is supporeted Ruby 4.0 and later, so the Rator support is works
only on Ruby 4.0 and later.

https://github.com/ruby/timeout/commit/54ff671c6c
2025-12-05 18:32:13 +00:00
Benoit Daloze 95ea3bd5ee [ruby/timeout] Only the timeout method should be public on the Timeout module
https://github.com/ruby/timeout/commit/cd51eac3ca
2025-12-05 11:35:21 +00:00
Hiroshi SHIBATA 2dcf1f74a4 [ruby/timeout] v0.4.4
https://github.com/ruby/timeout/commit/f42b47d383
2025-10-29 06:50:19 +00:00
Benoit Daloze 3b602c952d [ruby/timeout] Gracefully handle a call to ensure_timeout_thread_created in a signal handler
* Fixes the issue described in
  https://github.com/ruby/timeout/issues/17#issuecomment-1461498517
  for TruffleRuby and JRuby.
* CRuby is currently unable to use Timeout in a signal handler due to
  https://bugs.ruby-lang.org/issues/19473.

https://github.com/ruby/timeout/commit/7a48e1c079
2025-06-24 20:41:45 +00:00
Hiroshi SHIBATA 2f315667eb [ruby/timeout] Bump up v0.4.3
https://github.com/ruby/timeout/commit/607d8c6fbe
2024-12-16 03:53:22 +00:00
Cosmic OppaiandJeremy Evans f6b62d001a [ruby/timeout] removed the non numeric check
https://github.com/ruby/timeout/commit/7d2af46a00

Co-authored-by: Jeremy Evans <code@jeremyevans.net>
2024-12-03 06:49:57 +00:00
Cosmic OppaiandJeremy Evans 7dc7aab4e9 [ruby/timeout] updated doc string
https://github.com/ruby/timeout/commit/4be6423de4

Co-authored-by: Jeremy Evans <code@jeremyevans.net>
2024-12-03 06:49:56 +00:00
CosmicOppai b156efc2a6 [ruby/timeout] updated doc and kept the nil compatiability
https://github.com/ruby/timeout/commit/f992632cf3
2024-12-03 06:49:55 +00:00
CosmicOppai e7dd185e21 [ruby/timeout] refactor the change to raise for nil and type-errror and added tests
https://github.com/ruby/timeout/commit/ffc8d7c003
2024-12-03 06:49:55 +00:00
CosmicOppai 0f2cd39e68 [ruby/timeout] refactor the change to keep the compatability with nil and type-errror and added tests
https://github.com/ruby/timeout/commit/8342544979
2024-12-03 06:49:54 +00:00
CosmicOppai 203a023447 [ruby/timeout] added the check for negative sec
https://github.com/ruby/timeout/commit/8e57887eee
2024-12-03 06:49:53 +00:00
Hiroshi SHIBATA 0c59048b3a [ruby/timeout] Bump up v0.4.2
https://github.com/ruby/timeout/commit/2f52522994
2024-11-06 08:26:55 +00:00
Olle Jonsson b5646124b3 [ruby/timeout] timeout.rb: Update documentation
This is a followup to #49.

https://github.com/ruby/timeout/commit/683fdb45ee
2024-08-28 10:58:23 +00:00
Nobuyoshi Nakada bb6cf76362 [ruby/timeout] [DOC] Missing documents
https://github.com/ruby/timeout/commit/301ad4cfdc
2023-12-25 21:12:49 +09:00
Hiroshi SHIBATA acf0f8551e [ruby/timeout] Bump up 0.4.1
https://github.com/ruby/timeout/commit/a65e49cc31
2023-11-07 04:56:40 +00:00
Hiroshi SHIBATA b7375770ef [ruby/timeout] Bump up v0.4.0
https://github.com/ruby/timeout/commit/413194f8d2
2023-06-23 03:52:03 +00:00
Jeremy EvansandNobuyoshi Nakada e8c9385123 [ruby/timeout] Raise exception instead of throw/catch for timeouts
(https://github.com/ruby/timeout/pull/30)

throw/catch is used for non-local control flow, not for exceptional situations.
For exceptional situations, raise should be used instead.  A timeout is an
exceptional situation, so it should use raise, not throw/catch.

Timeout's implementation that uses throw/catch internally causes serious problems.
Consider the following code:

```ruby
def handle_exceptions
  yield
rescue Exception => exc
  handle_error # e.g. ROLLBACK for databases
  raise
ensure
  handle_exit unless exc # e.g. COMMIT for databases
end

Timeout.timeout(1) do
  handle_exceptions do
    do_something
  end
end
```

This kind of design ensures that all exceptions are handled as errors, and
ensures that all exits (normal exit, early return, throw/catch) are not
handled as errors.  With Timeout's throw/catch implementation, this type of
code does not work, since a timeout triggers the normal exit path.

See https://github.com/rails/rails/pull/29333 for an example of the damage
Timeout's design has caused the Rails ecosystem.

This switches Timeout.timeout to use raise/rescue internally.  It adds a
Timeout::ExitException subclass of exception for the internal raise/rescue,
which Timeout.timeout will convert to Timeout::Error for backwards
compatibility.  Timeout::Error remains a subclass of RuntimeError.

This is how timeout used to work in Ruby 2.0.  It was changed in Ruby 2.1,
after discussion in [Bug #8730] (commit
https://github.com/ruby/timeout/commit/238c003c921e in the timeout repository). I
think the change from using raise/rescue to using throw/catch has caused
significant harm to the Ruby ecosystem at large, and reverting it is
the most sensible choice.

From the translation of [Bug #8730], it appears the issue was that
someone could rescue Exception and not reraise the exception, causing
timeout errors to be swallowed.  However, such code is broken anyway.
Using throw/catch causes far worse problems, because then it becomes
impossible to differentiate between normal control flow and exceptional
control flow.

Also related to this is [Bug #11344], which changed how
Thread.handle_interrupt interacted with Timeout.

https://github.com/ruby/timeout/commit/f16545abe6

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2023-06-22 18:24:46 +00:00
Hiroshi SHIBATA 65b6411e9d [ruby/timeout] bump up 0.3.2
https://github.com/ruby/timeout/commit/e1b2448101
2023-02-16 00:57:08 +00:00
Rick Blommers 610375edfc [ruby/timeout] Don't move the timer_thread when it's enclosed
Don't move the timer_thread to ThreadGroup::Default, when it's
created in an enclosed ThreadGroup.
Prevents the exception: "add" can't move from the enclosed thread group"

https://github.com/ruby/timeout/commit/eb889d2c8b
2023-02-15 19:25:05 +00:00
Hiroshi SHIBATA 3909cfaa02 [ruby/timeout] Bump version to 0.3.1
https://github.com/ruby/timeout/commit/4941e8c871
2022-12-05 08:13:18 +00:00
Lars Kanis 9d56d9975d [ruby/timeout] Explicit add the timeout thread to default ThreadGroup
Otherwise the timeout thread would be added to the ThreadGroup of the thread that makes the first call to Timeout.timeout .

Fixes bug 19020: https://bugs.ruby-lang.org/issues/19020

Add a test case to make sure the common thread doesn't leak to another ThreadGroup

https://github.com/ruby/timeout/commit/c4f1385c9a
2022-09-28 01:59:35 +09:00
Jean Boussier 8290d76647 [ruby/timeout] Give a name to the background thread
https://github.com/ruby/timeout/commit/5594ae2f4d
2022-07-13 21:16:15 +09:00
Jean Boussier 4e21b19a61 [ruby/timeout] Keep a private reference to Process.clock_gettime
`timeout 0.3.0` broke our test suite because we have some
tests that stubs `Process.clock_gettime` making it return
a value in the past, causing `Timeout` to trigger almost immediately.

I beleive it wasn't a problem before because it was relying on `Process.sleep`.

https://github.com/ruby/timeout/commit/e5911a303e
2022-06-09 18:58:49 +09:00
Nobuyoshi Nakada cd6f87eefc [ruby/timeout] Set the flag surely before return
https://github.com/ruby/timeout/commit/f3a31abdfb
2022-05-25 19:50:47 +09:00
Nobuyoshi Nakada e77e233935 [ruby/timeout] Hack to avoid leak checker
https://github.com/ruby/timeout/commit/9a9b03b44c
2022-05-25 18:47:26 +09:00
Hiroshi SHIBATA fde4519af8 [ruby/timeout] Bump version to 0.3.0
https://github.com/ruby/timeout/commit/f69f954a94
2022-05-25 18:08:01 +09:00
Benoit Daloze 75fcfb1416 [ruby/timeout] Remove redundant done? check
* It's already checked inside #interrupt.

https://github.com/ruby/timeout/commit/5f43254f81
2022-05-19 07:19:42 +09:00
Benoit Daloze 240ac9eaa8 [ruby/timeout] Synchronize all accesses to @done
* So it is trivially correct.
* Performance seems the same overall.

https://github.com/ruby/timeout/commit/5e0d8e1637
2022-05-19 07:19:41 +09:00
Benoit Daloze 354cd6f210 [ruby/timeout] Handle Timeout + fork and add test for it
https://github.com/ruby/timeout/commit/4baee63b9b
2022-05-19 07:19:40 +09:00
Benoit Daloze 89fbec224d [ruby/timeout] Reimplement Timeout.timeout with a single thread and a Queue
https://github.com/ruby/timeout/commit/2bafc458f1
2022-05-19 07:19:39 +09:00
Hiroshi SHIBATA 2c75fc915e [ruby/timeout] Bump up timeout version to 0.2.0
https://github.com/ruby/timeout/commit/02e792ddd8
2021-10-14 20:12:29 +09:00
rm155 0a38212e57 [ruby/timeout] Freeze VERSION
https://github.com/ruby/timeout/commit/ac7b010c41
2021-09-27 19:36:20 +09:00
Jeremy Evans 120b835fae [ruby/timeout] Only run timeout_after hook on fiber scheduler if scheduler exists
https://github.com/ruby/timeout/commit/4893cde0ed
2021-05-06 16:51:10 +09:00
Jeremy Evans 44e8575ca6 [ruby/timeout] Avoid unnecessary object allocation
Idea from nobu.

https://github.com/ruby/timeout/commit/aecdaa23b3
2021-05-06 16:50:31 +09:00
Jeremy Evans 33b5e179a8 [ruby/timeout] Make Timeout::Error#exception with multiple arguments not ignore arguments
This makes:

  raise(Timeout::Error.new("hello"), "world")

raise a TimeoutError instance with "world" as the message instead
of "hello", for consistency with other Ruby exception classes.

This required some internal changes to keep the tests passing.

Fixes [Bug #17812]

https://github.com/ruby/timeout/commit/952154dbf9
2021-05-06 16:49:26 +09:00
Samuel Williams 92449e0e99 Fix handling of timeout accessing scheduler outside of non-blocking context. 2021-03-30 18:38:42 +13:00