61 Commits
Author SHA1 Message Date
Étienne Barrié 4ce8515c69 [ruby/timeout] Remove warnings
https://github.com/ruby/timeout/commit/9b935535ff
2026-03-09 12:09:50 +00:00
Benoit Daloze b5ffaa3a01 [ruby/timeout] Fix timing-dependent test
* The timeout could trigger before the `raise`.

https://github.com/ruby/timeout/commit/e4aa36096f
2026-03-09 12:05:38 +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
t-mangoe 44a1765684 [ruby/timeout] add test case for string argument
https://github.com/ruby/timeout/commit/fef9d07f44
2025-12-26 11:00:51 +09:00
Benoit Daloze 175a0d5f1a [ruby/timeout] Restore original signal handler in test_timeout_in_trap_handler
https://github.com/ruby/timeout/commit/4ae8631acf
2025-12-12 08:39:02 +00:00
Luke Gruber dc58d58a72 [ruby/timeout] Fix failing timeout test
```
Run options:
  "--ruby=./miniruby -I../ruby/lib -I. -I.ext/common  ../ruby/tool/runruby.rb --extout=.ext  -- --disable-gems"
  --excludes-dir=../ruby/test/.excludes
  --name=!/memory_leak/
  --seed=9843

[ 1/31] TestTimeout#test_timeout_in_trap_handler = 0.00 s
1) Error:
TestTimeout#test_timeout_in_trap_handler:
NoMethodError: undefined method 'kill' for nil
    /Users/luke/workspace/ruby-dev/ruby/test/test_timeout.rb:9:in 'TestTimeout#kill_timeout_thread'
    /Users/luke/workspace/ruby-dev/ruby/test/test_timeout.rb:424:in 'TestTimeout#test_timeout_in_trap_handler'

Finished tests in 2.715032s, 11.4179 tests/s, 52.3014 assertions/s.
31 tests, 142 assertions, 0 failures, 1 errors, 0 skips

ruby -v: ruby 4.0.0dev (2025-12-11T21:56:23Z fix_timeout_test https://github.com/ruby/timeout/commit/1c5eacbf9a) +PRISM [arm64-darwin24]
make: *** [yes-test-all] Error 1
```

https://github.com/ruby/timeout/commit/e5bc1de901
2025-12-11 22:21:26 +00:00
Jean Boussier fb80587f88 [ruby/timeout] Add windows to CI matrix
https://github.com/ruby/timeout/commit/c8d63ce3fe
2025-12-11 20:45:58 +00:00
Jean Boussier 1b7c8b7993 [ruby/timeout] Skip signal test on windows
Windows has no SIGUSR1.

There might be another usable signal, but this is breaking ruby master
so I just want a quick fix for now.

https://github.com/ruby/timeout/commit/b19043e8d0
2025-12-11 20:21:21 +00: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 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
Koichi Sasada bd752290e7 [ruby/timeout] Revert "Exclude constantly-failing test on x86_64-darwin"
This reverts commit https://github.com/ruby/timeout/commit/45816b1b2602.

https://github.com/ruby/timeout/commit/b54f91e9dd
2025-12-08 17:06:19 +00:00
Benoit Daloze aae8592650 [ruby/timeout] Test that Timeout does not expose extra constants
https://github.com/ruby/timeout/commit/4de4b4759c
2025-12-06 10:11:45 +00:00
Benoit Daloze 65995c22f8 [ruby/timeout] Exclude constantly-failing test on x86_64-darwin
* https://github.com/ruby/ruby-dev-builder/actions/runs/19973218359/job/57293388626

https://github.com/ruby/timeout/commit/45816b1b26
2025-12-05 22:09:52 +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
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
Nobuyoshi Nakada c85eb2d0d0 [ruby/timeout] Revert "Suppress warnings in two tests"
This reverts commit https://github.com/ruby/timeout/commit/983cbf636a17, that is
fixed by test-unit 3.7.3.

https://github.com/ruby/timeout/commit/095207f270
2025-11-26 09:55:51 +00:00
Olle Jonsson bc177ff1ce [ruby/timeout] Suppress warnings in two tests
Failed build in #70.

Pre-3.0 versions of Ruby didn't support pattern matching, and power_assert warned.

https://github.com/ruby/timeout/commit/983cbf636a
2025-11-10 08:31:11 +00:00
Koichi Sasada 46f3d82f40 Revert "try to show timeout sec"
This reverts commit ce66eea167.
2025-03-05 05:45:54 +09:00
Koichi Sasada ce66eea167 try to show timeout sec
http://ci.rvm.jp/results/trunk-gc-asserts@ruby-sp2-noble-docker/5632508
```
  1) Error:
TestEval#test_outer_local_variable_under_gc_compact_stress:
Test::Unit::ProxyError: execution of Test::Unit::CoreAssertions#assert_separately expired timeout (10 sec)
pid 1339179 killed by SIGABRT (signal 6) (core dumped)
```

seems that timeout scale doesn't work even though `RUBY_TEST_TIMEOUT_SCALE`
is specified.

This patch tries to print the timeout with scale information.
2025-03-04 19:39:16 +09:00
CosmicOppai e97225b182 [ruby/timeout] updated tests
https://github.com/ruby/timeout/commit/c6d121aa18
2024-12-03 06:49:56 +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 0839eae2d3 [ruby/timeout] refactor the change to keep the compatability with nil and type-errror and added tests
https://github.com/ruby/timeout/commit/e8a7dbdb87
2024-12-03 06:49:54 +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
Yusuke Endoh 2114d0af1e Make test_nested_timeouts less flaky
This test randomly fails due to the bug reported in [Bug #20314], where
the two timeouts are too close so that they can expire at the same time.

As a workaround, this change increases the time difference between
timeouts. This will reduce the probability of simultaneous expirations
and lower flakiness.
2024-05-28 12:49:46 +09:00
Yusuke Endoh 7f565b923a Prevent a warning: assigned but unused variable - raised_exception 2023-11-08 15:39:19 +09:00
John Bachir 77f9086768 [ruby/timeout] tests for blank seconds
https://github.com/ruby/timeout/commit/54bc7639d2
2023-11-07 15:29:58 +09:00
John Bachir f26e89c4a7 [ruby/timeout] nested exception tests for discussion
https://github.com/ruby/timeout/commit/3e42aa4d84
2023-11-07 04:45:29 +00:00
John Bachir 8281f8fd06 [ruby/timeout] Test that work is done in the same thread/fiber as
the caller
(https://github.com/ruby/timeout/pull/34)

* see discussion in
https://github.com/ruby/timeout/pull/30#issuecomment-1616179651
2023-07-03 09:26:43 +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
Benoit Daloze 70d84a5f3d [ruby/timeout] Simplify test
https://github.com/ruby/timeout/commit/db017da726
2023-02-15 19:25:05 +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
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
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
John Bachir 1147136b8a [ruby/timeout] test that yield is given number of seconds
https://github.com/ruby/timeout/commit/ec5a614334
2021-09-28 06:05:50 +09:00
John Bachir 582602d142 [ruby/timeout] test for basic functionality
https://github.com/ruby/timeout/commit/1c6bb90aea
2021-09-27 13:22:46 +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
kazu 6064132c42 Remove unnecessary require 'thread'
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60139 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-08 07:00:01 +00:00
kazu d6e4975eaf Use our domain instead of other's domain
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56093 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-07 12:32:04 +00:00
nobu 047ca4ba1a timeout.rb: custom error message
* lib/timeout.rb (Timeout#timeout): add custom error message
  argument.  [Feature #11650]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56089 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-07 08:21:56 +00:00
nobu 4b298ad77a Use qualified names
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56037 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-08-30 06:22:30 +00:00
naruse 3e92b635fb Add frozen_string_literal: false for all files
When you change this to true, you may need to add more tests.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-16 05:07:31 +00:00
nobu e0d6328ff4 test_timeout.rb: exact messages
* test/test_timeout.rb (test_rescue_exit, test_custom_exception):
  assert with exact messages.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52433 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-03 12:15:31 +00:00
nobu beb1c085d5 use Timeout.timeout
* time: Object#timeout has been deprecated a long time ago, use
  Timeout.timeout.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51225 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-13 10:07:01 +00:00
nobu 8d7058db47 test_timeout.rb: add an assertion
* test/test_timeout.rb (test_custom_exception): assert that the
  given exception will raise on timeout.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51214 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-10 23:47:55 +00:00
nobu 0f663b2449 timeout.rb: removed and use Timeout::Error
* lib/timeout.rb (ExitException): removed internal exception class
  and use Timeout::Error instead, as using throw/catch to isolate
  each timeouts now.  [ruby-dev:49179] [Bug #11344]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-10 13:05:53 +00:00
nobu bd77dbc37a test_thread.rb: move thread switch test
* test/ruby/test_thread.rb (test_switch_while_busy_loop): move
  from test/test_timeout.rb.  [Bug #1402]

* test/test_timeout.rb (test_timeout): no longer related to
  [Bug #1402].  [Bug #8523]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46196 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-28 03:05:48 +00:00
hsbt 563ee01100 * test/test_timeout.rb (test_timeout): inverted test condition.
[Bug #8523]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46159 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-27 08:00:19 +00:00
nobu 3e9e4a6a96 lib/timeout.rb: fallback to Timeout::Error
* lib/timeout.rb (Timeout::ExitException.catch): pass arguments
  for new instance.
* lib/timeout.rb (Timeout::ExitException#exception): fallback to
  Timeout::Error if couldn't throw.  [ruby-dev:47872] [Bug #9380]
* lib/timeout.rb (Timeout#timeout): initialize ExitException with
  message for the fallback case.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44523 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-08 04:12:39 +00:00