Prevent event timestamps set to future

For scheduled events, the event timestamp is the intended timestamp. If
we force timer expiration, the timestamp might be in the future. Today,
this happens on shutdown. This change guarantees that event timestamps
are never set beyond network time.
This commit is contained in:
Jan Grashoefer 2025-04-11 13:06:33 +02:00
parent 3b478ddc0a
commit 3858a2920e
3 changed files with 11 additions and 6 deletions

View file

@ -3829,8 +3829,13 @@ ScheduleTimer::ScheduleTimer(const EventHandlerPtr& arg_event, Args arg_args, do
: Timer(t, TIMER_SCHEDULE), event(arg_event), args(std::move(arg_args)) {}
void ScheduleTimer::Dispatch(double /* t */, bool /* is_expire */) {
if ( event )
event_mgr.Enqueue(event, std::move(args), util::detail::SOURCE_LOCAL, 0, nullptr, this->Time());
if ( event ) {
// An event's intended timestamp might be in the past as timer expiration is driven by
// network time. Guarantee that the intended timestamp is never in the future (e.g.,
// when all timers are expired on shutdown).
auto ts = std::min(this->Time(), run_state::network_time);
event_mgr.Enqueue(event, std::move(args), util::detail::SOURCE_LOCAL, 0, nullptr, ts);
}
}
ScheduleExpr::ScheduleExpr(ExprPtr arg_when, EventExprPtr arg_event)