From 48b4ffc38ecef0d423a09967e6784adb5807033a Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 23 Mar 2021 13:36:50 +1030 Subject: [PATCH] timer: handle time going backwards. As seen in https://github.com/ElementsProject/lightning/issues/4401 OpenBSD 6.8 inside VirtualBox. Signed-off-by: Rusty Russell --- ccan/timer/timer.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ccan/timer/timer.c b/ccan/timer/timer.c index 48bded19..ef6b2774 100644 --- a/ccan/timer/timer.c +++ b/ccan/timer/timer.c @@ -108,13 +108,10 @@ void timer_addrel(struct timers *timers, struct timer *t, struct timerel rel) t->time = time_to_grains(timemono_add(time_mono(), rel)); -#if TIME_HAVE_MONOTONIC - assert(t->time >= timers->base); -#else /* Added in the past? Treat it as imminent. */ if (t->time < timers->base) t->time = timers->base; -#endif + if (t->time < timers->first) timers->first = t->time; @@ -346,7 +343,11 @@ struct timer *timers_expire(struct timers *timers, struct timemono expire) unsigned int off; struct timer *t; - assert(now >= timers->base); + /* This can happen without TIME_HAVE_MONOTONIC, but I also have + * a report of OpenBSD 6.8 under virtualbox doing this. */ + if (now < timers->base) { + return NULL; + } if (!timers->level[0]) { if (list_empty(&timers->far)) -- 2.39.2