Skip to content

Reject a NaN delay before it stops the global timer - #1133

Open
adityawrk wants to merge 1 commit into
ruby-concurrency:masterfrom
adityawrk:fix/reject-nan-delay
Open

adityawrk wants to merge 1 commit into
ruby-concurrency:masterfrom
adityawrk:fix/reject-nan-delay

Conversation

@adityawrk

@adityawrk adityawrk commented Nov 29, 2026 •

Copy link
Copy Markdown

Problem

ScheduledTask.execute(Float::NAN) is accepted. The task stays at the head of the global timer, process_tasks raises on [diff, 60].min because diff is NaN, and the loop ends. Later ScheduledTasks, TimerTasks, and Promises.schedule calls are queued and do not run.

NaN < 0.0 is false, so the existing "greater than zero" checks let it through. The same is true of TimerTask execution_interval= (NaN <= 0.0 is false) and of ScheduledTask#reschedule.

On current master, before this change:

nan_accepted=true
later_task_ran=false

A negative delay already raises ArgumentError with seconds must be greater than zero. A NaN delay should do the same, and a task scheduled after that rejection should still run.

Fix

Reject NaN in ScheduledTask#initialize, ScheduledTask#reschedule, and TimerTask#execution_interval=, using the same ArgumentError a negative delay raises. Zero and positive delays are unchanged.

After the change:

nan_raised=seconds must be greater than zero
timer_raised=must be greater than zero
reschedule_raised=seconds must be greater than zero delay=1.0
negative_raised=seconds must be greater than zero
zero=:zero
later=:ran

spec/concurrent/scheduled_task_spec.rb and spec/concurrent/timer_task_spec.rb: 125 examples, 0 failures.

Fixes #1131

…#1131)

A NaN delay compares as not less than zero, so ScheduledTask and
TimerTask accepted it. The task then stayed at the head of the global
timer and later scheduled work never ran.

This branch has not been deployed

No deployments
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.

ScheduledTask with a NaN delay stops the global TimerSet

1 participant