<feed xmlns='http://www.w3.org/2005/Atom'>
<title>ruby.git/test/test_timeout.rb, branch v3_4_9</title>
<subtitle>The Ruby Programming Language</subtitle>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/'/>
<entry>
<title>[ruby/timeout] updated tests</title>
<updated>2024-12-03T06:49:56+00:00</updated>
<author>
<name>CosmicOppai</name>
<email>cosmicoppai@protonmail.com</email>
</author>
<published>2024-10-17T19:40:34+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=e97225b18258dc81f38e0500ca819fec4791308a'/>
<id>e97225b18258dc81f38e0500ca819fec4791308a</id>
<content type='text'>
https://github.com/ruby/timeout/commit/c6d121aa18
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
https://github.com/ruby/timeout/commit/c6d121aa18
</pre>
</div>
</content>
</entry>
<entry>
<title>[ruby/timeout] refactor the change to raise for nil and type-errror and added tests</title>
<updated>2024-12-03T06:49:55+00:00</updated>
<author>
<name>CosmicOppai</name>
<email>cosmicoppai@protonmail.com</email>
</author>
<published>2024-10-15T00:51:18+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=e7dd185e2147ff0ce5ad6a3de563749a4ad8ccb2'/>
<id>e7dd185e2147ff0ce5ad6a3de563749a4ad8ccb2</id>
<content type='text'>
https://github.com/ruby/timeout/commit/ffc8d7c003
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
https://github.com/ruby/timeout/commit/ffc8d7c003
</pre>
</div>
</content>
</entry>
<entry>
<title>[ruby/timeout] refactor the change to keep the compatability with nil and type-errror and added tests</title>
<updated>2024-12-03T06:49:54+00:00</updated>
<author>
<name>CosmicOppai</name>
<email>cosmicoppai@protonmail.com</email>
</author>
<published>2024-10-14T10:54:21+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=0839eae2d362b70d1b36b939b7ad6aa809a618a9'/>
<id>0839eae2d362b70d1b36b939b7ad6aa809a618a9</id>
<content type='text'>
https://github.com/ruby/timeout/commit/e8a7dbdb87
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
https://github.com/ruby/timeout/commit/e8a7dbdb87
</pre>
</div>
</content>
</entry>
<entry>
<title>[ruby/timeout] refactor the change to keep the compatability with nil and type-errror and added tests</title>
<updated>2024-12-03T06:49:54+00:00</updated>
<author>
<name>CosmicOppai</name>
<email>cosmicoppai@protonmail.com</email>
</author>
<published>2024-10-14T10:53:53+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=0f2cd39e680c9b15ddd94d34770a8a17d0c5a0ae'/>
<id>0f2cd39e680c9b15ddd94d34770a8a17d0c5a0ae</id>
<content type='text'>
https://github.com/ruby/timeout/commit/8342544979
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
https://github.com/ruby/timeout/commit/8342544979
</pre>
</div>
</content>
</entry>
<entry>
<title>Make test_nested_timeouts less flaky</title>
<updated>2024-05-28T03:49:46+00:00</updated>
<author>
<name>Yusuke Endoh</name>
<email>mame@ruby-lang.org</email>
</author>
<published>2024-05-28T03:04:34+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=2114d0af1e5790da365584a38ea7ee58670dc11b'/>
<id>2114d0af1e5790da365584a38ea7ee58670dc11b</id>
<content type='text'>
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.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
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.
</pre>
</div>
</content>
</entry>
<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>
</feed>
