From: Willy Tarreau Date: Tue, 14 Jul 2009 21:48:55 +0000 (+0200) Subject: [BUG] task: fix possible timer drift after update X-Git-Tag: v1.4-dev1~14 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=814c978fb67782ceeaf1db74abfe7083938bedff;p=thirdparty%2Fhaproxy.git [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. --- diff --git a/src/task.c b/src/task.c index 5336c20e9d..3094fde7ef 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);