mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-06-11 11:56:18 +00:00
G5: F07 — await in-flight async callbacks before stop() returns
Why: EventDispatcher._process_events() calls task_done() on the queue immediately after spawning async callback tasks. await queue.join() in stop() therefore returns as soon as all items are marked done, even if their async callbacks are still executing. Any caller that does "await dispatcher.stop(); cleanup()" could race with still-running callbacks. Fix: after queue.join(), gather all tracked background tasks before cancelling the dispatch loop. Refs: Forensics report finding F07
This commit is contained in:
@@ -236,6 +236,10 @@ class EventDispatcher:
|
||||
self.running = False
|
||||
if self._task:
|
||||
await self.queue.join()
|
||||
# Wait for any in-flight async callbacks to complete before
|
||||
# tearing down (F07: task_done fires before callbacks finish).
|
||||
if self._background_tasks:
|
||||
await asyncio.gather(*self._background_tasks, return_exceptions=True)
|
||||
self._task.cancel()
|
||||
try:
|
||||
await self._task
|
||||
|
||||
Reference in New Issue
Block a user