You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cyw43_poll_worker can re-arm sleep_timeout_worker so the order of these is wrong. Not sure the lock is necessary but can't do any hard.
void cyw43_driver_deinit(async_context_t *context) {
if (cyw43_async_context != NULL) {
assert(context == cyw43_async_context);
- async_context_remove_at_time_worker(context, &sleep_timeout_worker);
+ async_context_acquire_lock_blocking(context);
async_context_remove_when_pending_worker(context, &cyw43_poll_worker);
+ async_context_remove_at_time_worker(context, &sleep_timeout_worker);
+ async_context_release_lock(context);
// the IRQ IS on the same core as the context, so must be de-initialized there
async_context_execute_sync(context, cyw43_irq_deinit, NULL);
cyw43_deinit(&cyw43_state);
I traced the worker lifecycle here. cyw43_do_poll() can re-add sleep_timeout_worker, so the current removal order is racy.
The FreeRTOS and threadsafe-background remove_* implementations already serialize through the context lock, so I think the minimal fix is to remove cyw43_poll_worker first and sleep_timeout_worker second, without adding an outer lock.
Once async_context_remove_when_pending_worker() returns, an active poll has completed under the context lock and that worker can no longer re-arm the timeout. Removing sleep_timeout_worker second then closes the remaining edge.
This also avoids broadening the lock around teardown / execute_sync(), which the cyw43_arch_* deinit comments explicitly warn about.
I'd add a regression that repeatedly init/deinits with the poll path pending and verifies neither worker can fire after deinit.
The change removes cyw43_poll_worker before sleep_timeout_worker. Since cyw43_do_poll() is what can re-arm the timeout, stopping that worker first closes the teardown race without adding a broader lock around execute_sync().
Activity
kvnloo commentedon Sep 29, 2026
I traced the worker lifecycle here.
cyw43_do_poll()can re-addsleep_timeout_worker, so the current removal order is racy.The FreeRTOS and threadsafe-background
remove_*implementations already serialize through the context lock, so I think the minimal fix is to removecyw43_poll_workerfirst andsleep_timeout_workersecond, without adding an outer lock.Once
async_context_remove_when_pending_worker()returns, an active poll has completed under the context lock and that worker can no longer re-arm the timeout. Removingsleep_timeout_workersecond then closes the remaining edge.This also avoids broadening the lock around teardown /
execute_sync(), which thecyw43_arch_*deinit comments explicitly warn about.I'd add a regression that repeatedly init/deinits with the poll path pending and verifies neither worker can fire after deinit.
kvnloo commentedon Sep 29, 2026
I sent a focused fix in #3215.
The change removes
cyw43_poll_workerbeforesleep_timeout_worker. Sincecyw43_do_poll()is what can re-arm the timeout, stopping that worker first closes the teardown race without adding a broader lock aroundexecute_sync().