From 4de2dea8076782d0685cd1f25edfb961d3a9d40c Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 14 Jul 2009 23:48:55 +0200 Subject: [PATCH] [BUG] task: fix possible timer drift after update When the scheduler detected that a task was misplaced in the timer queue, it used to place it right again. Unfortunately, it did not check whether it would still call the new task from its new place. This resulted in some tasks not getting called on timeout once in a while, causing a minor drift for repetitive timers. This effect was only observable with slow health checks and without any activity because no other task would cause the scheduler to be immediately called again. In practice, it does not affect any real-world configuration, but it's still better to fix it. (cherry picked from commit 814c978fb67782ceeaf1db74abfe7083938bedff) --- src/task.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/task.c b/src/task.c index 5336c20e9..3094fde7e 100644 --- a/src/task.c +++ b/src/task.c @@ -152,10 +152,14 @@ void wake_expired_tasks(int *next) * lot cheaper to proceed like this because we almost never update * the tree. We may also find disabled expiration dates there. Since * we have detached the task from the tree, we simply call task_queue - * to take care of this. + * to take care of this. Note that we might occasionally requeue it at + * the same place, before , so we have to check if this happens, + * and adjust , otherwise we may skip it which is not what we want. */ if (!tick_is_expired(task->expire, now_ms)) { task_queue(task); + if (!eb || eb->key > task->wq.key) + eb = &task->wq; continue; } task_wakeup(task, TASK_WOKEN_TIMER);