From 9615f5b3480c91eb229441adf13b17346a0f7a4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Thu, 7 Mar 2024 13:39:46 +0100 Subject: [PATCH] Don't loop indefinitely when isc_task quantum is 'unlimited' Don't run more events than already scheduled. If the quantum is set to a high value, the task_run() would execute already scheduled, and all new events that result from running event->ev_action(). Setting quantum to a number of scheduled events will postpone events scheduled after we enter the loop here to the next task_run() invocation. --- lib/isc/task.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/isc/task.c b/lib/isc/task.c index 48c3e790f4..fbee3f03a9 100644 --- a/lib/isc/task.c +++ b/lib/isc/task.c @@ -793,6 +793,18 @@ task_run(isc_task_t *task) { LOCK(&task->lock); quantum = task->quantum; + /* + * Don't run more events than already scheduled. If the quantum is set + * to a high value, the following code would execute already scheduled, + * and all events that result from running event->ev_action(). Setting + * quantum to a number of scheduled events will postpone events + * scheduled after we enter the loop here to the next task_run() + * invocation. + */ + if (quantum > task->nevents) { + quantum = task->nevents; + } + if (task->state != task_state_ready) { goto done; }