From 9227347b90a27dac0f52248d5ad55e7d67a34c6c Mon Sep 17 00:00:00 2001 From: Joris Vink Date: Mon, 7 Dec 2020 11:11:21 +0100 Subject: [PATCH] Fix concurrency problem in coroutines. If a coroutine is woken up from another coroutine running from an http request we can end up in a case where the call path looks like: 0 kore_worker_entry 1 epoll wait <- bound to pending timers 2 http_process <- first coro sleep 3 kore_python_coro_run <- wakes up request 4 http_process <- wakes up another coroutine 5 return to kore_worker_entry In the case where 4 wakes up another coroutine but 1 is bound to a timer and no io activity occurs the coroutine isn't run until the timer fires. Fix this issue by always checking for pending coroutines even if the netwait isn't INFINITE. --- src/worker.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/worker.c b/src/worker.c index a04bdd4..7fe1e0b 100644 --- a/src/worker.c +++ b/src/worker.c @@ -474,13 +474,14 @@ kore_worker_entry(struct kore_worker *kw) #if !defined(KORE_NO_HTTP) if (http_request_count > 0) netwait = 100; -#endif -#if defined(KORE_USE_PYTHON) - if (kore_python_coro_pending()) - netwait = 10; #endif } +#if defined(KORE_USE_PYTHON) + if (kore_python_coro_pending()) + netwait = 0; +#endif + kore_platform_event_wait(netwait); now = kore_time_ms();