Skip to content

Reject NaN timeout durations before scheduling - #119

Open
OskarEichler wants to merge 1 commit into
ruby:masterfrom
OskarEichler:codex/nan-timeout
Open

Reject NaN timeout durations before scheduling#119
OskarEichler wants to merge 1 commit into
ruby:masterfrom
OskarEichler:codex/nan-timeout

Conversation

@OskarEichler

Copy link
Copy Markdown

Summary

Reject NaN before creating a timeout request or delegating to a fiber scheduler. Test for a non-negative comparison instead of only testing for a negative comparison; NaN satisfies neither.

Reproduction

require 'timeout'
ran = false
begin
  Timeout.timeout(Float::NAN) { ran = true }
rescue => error
  p error.class # after: ArgumentError
end
p ran # before: true; after: false

With an active block, the old request has a NaN deadline: neither its wait condition nor its expiry comparison succeeds, so the watcher repeatedly revisits it. An isolated bounded reproduction observed the watcher running until the request was cancelled. No throughput/CPU benchmark claim is made.

Focused checks cover both exception modes, nil/zero/positive integer/float/rational values, negative/infinite-negative values and rejection before scheduler delegation.

Verification

  • Ruby 4.0.6 via rbenv; reviewed master 295667aac44220ddfd10db014e766ae8d313cfb8.
  • Existing bundle exec rake test: 36 tests / 81 assertions / zero failures or errors, baseline and this branch. Includes the existing signal, fork, Ractor, exception and mocked-scheduler cases.
  • nan: 15 checks, 0 failures in a disposable external script, with the affected expectations reproduced before the change.
  • Syntax and git diff --check pass. Supplemental RuboCop Lint retains the same two existing offenses; no lint-clean claim.
  • No repository tests added/modified, following the consuming project's explicit no-new-tests instruction. Standalone reproduction is included above.
  • Existing issues/PRs checked, including multi threaded use of timeout leads to OOM on high throughput scenarios #58 throughput, Handle nested timeout calls with the same duration #91 nested-timeout draft, Ensure thread is released on completion #114 completed-thread retention, and historic comparison/deferred-exception changes. No duplicate retention or nested-timeout proposal.

Compatibility and limitations

NaN now raises ArgumentError without yielding, matching the documented non-negative-number requirement. Negative inputs retain that error. This does not restore the Numeric class restriction removed in 7d2af46; existing duck typing and zero/nil behavior remain. Positive infinity and very large intervals are a separate issue, not fixed in this PR.

The same runtime file is shipped in 0.6.1; this patch can be adopted without a release upgrade. Ruby >= 2.6 and the empty runtime dependency set remain unchanged. No production access or external network diagnostic was used; other Ruby/OS combinations and full scheduler implementations were not run locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant