ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [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
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ 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] 5+ 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
  2024-11-18  4:33 ` [ruby-core:119953] " jeremyevans0 (Jeremy Evans) via ruby-core
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ 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] 5+ messages in thread

* [ruby-core:119953] [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 ` [ruby-core:119515] " Eregon (Benoit Daloze) via ruby-core
@ 2024-11-18  4:33 ` jeremyevans0 (Jeremy Evans) via ruby-core
  2024-12-03  6:49 ` [ruby-core:120085] " hsbt (Hiroshi SHIBATA) via ruby-core
  2024-12-03  6:51 ` [ruby-core:120086] " hsbt (Hiroshi SHIBATA) via ruby-core
  3 siblings, 0 replies; 5+ messages in thread
From: jeremyevans0 (Jeremy Evans) via ruby-core @ 2024-11-18  4:33 UTC (permalink / raw)
  To: ruby-core; +Cc: jeremyevans0 (Jeremy Evans)

Issue #20795 has been updated by jeremyevans0 (Jeremy Evans).


PR was filed for this: https://github.com/ruby/timeout/pull/51

----------------------------------------
Bug #20795: Timeout method doesn't check for negative time values
https://bugs.ruby-lang.org/issues/20795#change-110676

* 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] 5+ messages in thread

* [ruby-core:120085] [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 ` [ruby-core:119515] " Eregon (Benoit Daloze) via ruby-core
  2024-11-18  4:33 ` [ruby-core:119953] " jeremyevans0 (Jeremy Evans) via ruby-core
@ 2024-12-03  6:49 ` hsbt (Hiroshi SHIBATA) via ruby-core
  2024-12-03  6:51 ` [ruby-core:120086] " hsbt (Hiroshi SHIBATA) via ruby-core
  3 siblings, 0 replies; 5+ messages in thread
From: hsbt (Hiroshi SHIBATA) via ruby-core @ 2024-12-03  6:49 UTC (permalink / raw)
  To: ruby-core; +Cc: hsbt (Hiroshi SHIBATA)

Issue #20795 has been updated by hsbt (Hiroshi SHIBATA).


We discussed this with Matz at last developer meeting.

He said "Let's raise an `ArgumentError` against negative value". 

----------------------------------------
Bug #20795: Timeout method doesn't check for negative time values
https://bugs.ruby-lang.org/issues/20795#change-110834

* 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] 5+ messages in thread

* [ruby-core:120086] [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
                   ` (2 preceding siblings ...)
  2024-12-03  6:49 ` [ruby-core:120085] " hsbt (Hiroshi SHIBATA) via ruby-core
@ 2024-12-03  6:51 ` hsbt (Hiroshi SHIBATA) via ruby-core
  3 siblings, 0 replies; 5+ messages in thread
From: hsbt (Hiroshi SHIBATA) via ruby-core @ 2024-12-03  6:51 UTC (permalink / raw)
  To: ruby-core; +Cc: hsbt (Hiroshi SHIBATA)

Issue #20795 has been updated by hsbt (Hiroshi SHIBATA).

Status changed from Open to Closed
Backport changed from 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN to 3.1: DONTNEED, 3.2: DONTNEED, 3.3: DONTNEED

I merged https://github.com/ruby/timeout/pull/51 now. Thank you.

----------------------------------------
Bug #20795: Timeout method doesn't check for negative time values
https://bugs.ruby-lang.org/issues/20795#change-110835

* Author: kanakchaudhari12 (kanak chaudhari)
* Status: Closed
* ruby -v: 3.1.0
* Backport: 3.1: DONTNEED, 3.2: DONTNEED, 3.3: DONTNEED
----------------------------------------
```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] 5+ messages in thread

end of thread, other threads:[~2024-12-03  6:52 UTC | newest]

Thread overview: 5+ 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
2024-11-18  4:33 ` [ruby-core:119953] " jeremyevans0 (Jeremy Evans) via ruby-core
2024-12-03  6:49 ` [ruby-core:120085] " hsbt (Hiroshi SHIBATA) via ruby-core
2024-12-03  6:51 ` [ruby-core:120086] " hsbt (Hiroshi SHIBATA) 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).