* [ruby-core:119513] [Ruby master Bug#20795] Timeout method doesn't check for negative time values
@ 2024-10-12 19:07 kanakchaudhari12 (kanak chaudhari) via ruby-core
2024-10-13 16:46 ` [ruby-core:119515] " Eregon (Benoit Daloze) via ruby-core
0 siblings, 1 reply; 2+ messages in thread
From: kanakchaudhari12 (kanak chaudhari) via ruby-core @ 2024-10-12 19:07 UTC (permalink / raw)
To: ruby-core; +Cc: kanakchaudhari12 (kanak chaudhari)
Issue #20795 has been reported by kanakchaudhari12 (kanak chaudhari).
----------------------------------------
Bug #20795: Timeout method doesn't check for negative time values
https://bugs.ruby-lang.org/issues/20795
* Author: kanakchaudhari12 (kanak chaudhari)
* Status: Open
* ruby -v: 3.1.0
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
```ruby
require 'timeout'
# Case 1: Negative timeout with quick execution
Timeout.timeout(-5) do
puts "This should not execute"
end
# Case 2: Negative timeout with sleep
Timeout.timeout(-5) do
sleep(10)
end
```
Potential issues with current behaviour:
* Inconsistency: The behaviour differs based on the block's content, which may not be immediately apparent
* Silent failure: The negative timeout is silently ignored, potentially masking logical errors in the calling code.
* Unexpected source of error: one might expect the timeout method to validate its input, rather than relying on methods called within the block to catch invalid time values.
I suggest this change for the consistent behaviour regardless of code-block as well as the clear indication of the source of the error
```ruby
def timeout(sec, klass = nil, message = nil, &block)
raise ArgumentError, "timeout must be positive" if sec.is_a?(Numeric) && sec < 0
# ...
end
```
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 2+ messages in thread
* [ruby-core:119515] [Ruby master Bug#20795] Timeout method doesn't check for negative time values
2024-10-12 19:07 [ruby-core:119513] [Ruby master Bug#20795] Timeout method doesn't check for negative time values kanakchaudhari12 (kanak chaudhari) via ruby-core
@ 2024-10-13 16:46 ` Eregon (Benoit Daloze) via ruby-core
0 siblings, 0 replies; 2+ messages in thread
From: Eregon (Benoit Daloze) via ruby-core @ 2024-10-13 16:46 UTC (permalink / raw)
To: ruby-core; +Cc: Eregon (Benoit Daloze)
Issue #20795 has been updated by Eregon (Benoit Daloze).
Could you make a PR to https://github.com/ruby/timeout ? (or if not open an issue there?)
----------------------------------------
Bug #20795: Timeout method doesn't check for negative time values
https://bugs.ruby-lang.org/issues/20795#change-110128
* Author: kanakchaudhari12 (kanak chaudhari)
* Status: Open
* ruby -v: 3.1.0
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
```ruby
require 'timeout'
# Case 1: Negative timeout with quick execution
Timeout.timeout(-5) do
puts "This should not execute"
end
# Case 2: Negative timeout with sleep
Timeout.timeout(-5) do
sleep(10)
end
```
Potential issues with current behaviour:
* Inconsistency: The behaviour differs based on the block's content, which may not be immediately apparent
* Silent failure: The negative timeout is silently ignored, potentially masking logical errors in the calling code.
* Unexpected source of error: one might expect the timeout method to validate its input, rather than relying on methods called within the block to catch invalid time values.
I suggest this change for the consistent behaviour regardless of code-block as well as the clear indication of the source of the error
```ruby
def timeout(sec, klass = nil, message = nil, &block)
raise ArgumentError, "timeout must be positive" if sec.is_a?(Numeric) && sec < 0
# ...
end
```
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-10-13 16:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-12 19:07 [ruby-core:119513] [Ruby master Bug#20795] Timeout method doesn't check for negative time values kanakchaudhari12 (kanak chaudhari) via ruby-core
2024-10-13 16:46 ` [ruby-core:119515] " Eregon (Benoit Daloze) via ruby-core
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 NNTP newsgroup(s).