diff --git a/src/Expr.cc b/src/Expr.cc index 88c2bbd759..9e872d846f 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -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) diff --git a/testing/btest/Baseline/broker.remote_event_schedule_ts/send.send.out b/testing/btest/Baseline/broker.remote_event_schedule_ts/send.send.out index 68fdce6f5b..2135ed1cd8 100644 --- a/testing/btest/Baseline/broker.remote_event_schedule_ts/send.send.out +++ b/testing/btest/Baseline/broker.remote_event_schedule_ts/send.send.out @@ -39,5 +39,5 @@ sender added peer: endpoint=127.0.0.1 msg=handshake successful >> Run 10 (1989-12-13-07:00:00) >>> Publish my-message-a intended for 1989-12-13-07:00:00 (current_event_time=1989-12-13-07:00:00, network_time=1989-12-13-07:00:00) sender lost peer: endpoint=127.0.0.1 msg=lost connection to remote peer ->>> Publish my-message-b intended for 1989-12-13-07:15:00 (current_event_time=1989-12-13-07:15:00, network_time=1989-12-13-07:00:00) ->>> Publish my-message-c intended for 1989-12-13-07:30:00 (current_event_time=1989-12-13-07:30:00, network_time=1989-12-13-07:00:00) +>>> Publish my-message-b intended for 1989-12-13-07:15:00 (current_event_time=1989-12-13-07:00:00, network_time=1989-12-13-07:00:00) +>>> Publish my-message-c intended for 1989-12-13-07:30:00 (current_event_time=1989-12-13-07:00:00, network_time=1989-12-13-07:00:00) diff --git a/testing/btest/Baseline/language.event-ts-scheduled/out b/testing/btest/Baseline/language.event-ts-scheduled/out index 6890f28697..0b94b35b83 100644 --- a/testing/btest/Baseline/language.event-ts-scheduled/out +++ b/testing/btest/Baseline/language.event-ts-scheduled/out @@ -37,5 +37,5 @@ [1989-12-13-07:00:00] Test was scheduled at 1989-12-13-06:00:00 for 1989-12-13-06:30:00 >> Run 9 (1989-12-13-07:00:00) << Run 9 (1989-12-13-07:00:00) -[1989-12-13-07:00:00] Test was scheduled at 1989-12-13-07:00:00 for 1989-12-13-07:15:00 -[1989-12-13-07:00:00] Test was scheduled at 1989-12-13-07:00:00 for 1989-12-13-07:30:00 +[1989-12-13-07:00:00] Test was scheduled at 1989-12-13-07:00:00 for 1989-12-13-07:00:00 +[1989-12-13-07:00:00] Test was scheduled at 1989-12-13-07:00:00 for 1989-12-13-07:00:00