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.
This commit is contained in:
Joris Vink 2020-12-07 11:11:21 +01:00
parent fd2cda5a43
commit 9227347b90
1 changed files with 5 additions and 4 deletions

View File

@ -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();