<feed xmlns='http://www.w3.org/2005/Atom'>
<title>ruby.git/test/test_timeout.rb, branch v3_3_11</title>
<subtitle>The Ruby Programming Language</subtitle>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/'/>
<entry>
<title>Prevent a warning: assigned but unused variable - raised_exception</title>
<updated>2023-11-08T06:39:19+00:00</updated>
<author>
<name>Yusuke Endoh</name>
<email>mame@ruby-lang.org</email>
</author>
<published>2023-11-08T06:39:19+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=7f565b923a62638e76b053f996e7149ec035b63d'/>
<id>7f565b923a62638e76b053f996e7149ec035b63d</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>[ruby/timeout] tests for blank seconds</title>
<updated>2023-11-07T06:29:58+00:00</updated>
<author>
<name>John Bachir</name>
<email>j@jjb.cc</email>
</author>
<published>2023-07-09T06:03:55+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=77f90867687725578e25c28ec15580912c4ba93b'/>
<id>77f90867687725578e25c28ec15580912c4ba93b</id>
<content type='text'>
https://github.com/ruby/timeout/commit/54bc7639d2
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
https://github.com/ruby/timeout/commit/54bc7639d2
</pre>
</div>
</content>
</entry>
<entry>
<title>[ruby/timeout] nested exception tests for discussion</title>
<updated>2023-11-07T04:45:29+00:00</updated>
<author>
<name>John Bachir</name>
<email>j@jjb.cc</email>
</author>
<published>2023-07-04T19:45:28+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=f26e89c4a76b628d36b8389a4c9462de97cf4f12'/>
<id>f26e89c4a76b628d36b8389a4c9462de97cf4f12</id>
<content type='text'>
https://github.com/ruby/timeout/commit/3e42aa4d84
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
https://github.com/ruby/timeout/commit/3e42aa4d84
</pre>
</div>
</content>
</entry>
<entry>
<title>[ruby/timeout] Test that work is done in the same thread/fiber as</title>
<updated>2023-07-03T09:26:43+00:00</updated>
<author>
<name>John Bachir</name>
<email>jjb@users.noreply.github.com</email>
</author>
<published>2023-07-03T09:26:40+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=8281f8fd067017ac909bd16a66e64cfdfed06bc8'/>
<id>8281f8fd067017ac909bd16a66e64cfdfed06bc8</id>
<content type='text'>
the caller
(https://github.com/ruby/timeout/pull/34)

* see discussion in
https://github.com/ruby/timeout/pull/30#issuecomment-1616179651
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
the caller
(https://github.com/ruby/timeout/pull/34)

* see discussion in
https://github.com/ruby/timeout/pull/30#issuecomment-1616179651
</pre>
</div>
</content>
</entry>
<entry>
<title>[ruby/timeout] Raise exception instead of throw/catch for timeouts</title>
<updated>2023-06-22T18:24:46+00:00</updated>
<author>
<name>Jeremy Evans</name>
<email>code@jeremyevans.net</email>
</author>
<published>2023-06-22T18:24:40+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=e8c9385123d6f7678b8c37f5543933703907abd2'/>
<id>e8c9385123d6f7678b8c37f5543933703907abd2</id>
<content type='text'>
(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 =&gt; 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 &lt;nobu@ruby-lang.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
(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 =&gt; 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 &lt;nobu@ruby-lang.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>[ruby/timeout] Simplify test</title>
<updated>2023-02-15T19:25:05+00:00</updated>
<author>
<name>Benoit Daloze</name>
<email>eregontp@gmail.com</email>
</author>
<published>2023-02-15T18:26:13+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=70d84a5f3deab5caaeb88134e9d90b1dca4a0462'/>
<id>70d84a5f3deab5caaeb88134e9d90b1dca4a0462</id>
<content type='text'>
https://github.com/ruby/timeout/commit/db017da726
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
https://github.com/ruby/timeout/commit/db017da726
</pre>
</div>
</content>
</entry>
<entry>
<title>[ruby/timeout] Don't move the timer_thread when it's enclosed</title>
<updated>2023-02-15T19:25:05+00:00</updated>
<author>
<name>Rick Blommers</name>
<email>rick@blommersit.nl</email>
</author>
<published>2023-02-12T14:23:37+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=610375edfc2ed487dc5798278a5923154aec1c1f'/>
<id>610375edfc2ed487dc5798278a5923154aec1c1f</id>
<content type='text'>
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
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
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
</pre>
</div>
</content>
</entry>
<entry>
<title>[ruby/timeout] Explicit add the timeout thread to default ThreadGroup</title>
<updated>2022-09-27T16:59:35+00:00</updated>
<author>
<name>Lars Kanis</name>
<email>lars@greiz-reinsdorf.de</email>
</author>
<published>2022-09-25T09:14:11+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=9d56d9975d867c94ab2a6d76e4482112ab6c3319'/>
<id>9d56d9975d867c94ab2a6d76e4482112ab6c3319</id>
<content type='text'>
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
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
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
</pre>
</div>
</content>
</entry>
<entry>
<title>[ruby/timeout] Handle Timeout + fork and add test for it</title>
<updated>2022-05-18T22:19:40+00:00</updated>
<author>
<name>Benoit Daloze</name>
<email>eregontp@gmail.com</email>
</author>
<published>2022-05-15T11:43:29+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=354cd6f210c966327b1adffc0b81990827b77a0d'/>
<id>354cd6f210c966327b1adffc0b81990827b77a0d</id>
<content type='text'>
https://github.com/ruby/timeout/commit/4baee63b9b
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
https://github.com/ruby/timeout/commit/4baee63b9b
</pre>
</div>
</content>
</entry>
<entry>
<title>[ruby/timeout] Reimplement Timeout.timeout with a single thread and a Queue</title>
<updated>2022-05-18T22:19:39+00:00</updated>
<author>
<name>Benoit Daloze</name>
<email>eregontp@gmail.com</email>
</author>
<published>2022-05-12T14:20:56+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=89fbec224d8e1fa35e82bf2712c5a5fd3dc06b83'/>
<id>89fbec224d8e1fa35e82bf2712c5a5fd3dc06b83</id>
<content type='text'>
https://github.com/ruby/timeout/commit/2bafc458f1
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
https://github.com/ruby/timeout/commit/2bafc458f1
</pre>
</div>
</content>
</entry>
</feed>
