Skip to content

Bug: until() deadline counts time spent paused #22

Description

@ZialeHub

Description

The until() limit is checked as now - created_at >= limit. This uses wall-clock elapsed time from creation, which includes any time the task spent paused. Pausing a task therefore burns its until() budget,
causing it to expire earlier than intended.

Affected files

  • src/scheduler/async_scheduler.rs — lines 67–70
  • src/scheduler/sync_scheduler.rs — lines 67–70

Reproduction

  let id = scheduler.schedule(
      Box::new(task),
      every(1.seconds()).until(10.seconds()),
  ).unwrap();

  scheduler.pause(id).unwrap();
  std::thread::sleep(Duration::from_secs(9));
  scheduler.resume(id).unwrap();
  // Task now expires after ~1 more second of wall time, having barely run at all

Impact

A task configured to run "for 10 active seconds" will exit after 10 seconds of wall-clock time even if it was paused for 9 of those seconds.

Fix

Track the total paused duration and subtract it from the elapsed check:

  // In TaskDetails or the loop state:
  let effective_elapsed = (now - created_at) - total_paused_duration;
  if effective_elapsed.num_seconds() as u64 >= *limit { break; }

Or change the semantics to track an absolute stop-datetime computed at schedule time (analogous to until_datetime), so pause/resume don't affect it and the behavior is at least consistent and predictable
(document it clearly either way).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions