kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 9227347b90a27dac0f52248d5ad55e7d67a34c6c
parent fd2cda5a433f1f5ebfb1cecff7ce2e4f02940768
Author: Joris Vink <joris@coders.se>
Date:   Mon,  7 Dec 2020 11:11:21 +0100

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.

Diffstat:
src/worker.c | 7++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/worker.c b/src/worker.c @@ -475,11 +475,12 @@ kore_worker_entry(struct kore_worker *kw) if (http_request_count > 0) netwait = 100; #endif + } + #if defined(KORE_USE_PYTHON) - if (kore_python_coro_pending()) - netwait = 10; + if (kore_python_coro_pending()) + netwait = 0; #endif - } kore_platform_event_wait(netwait); now = kore_time_ms();