🛠 Fix: Properly retrieve exceptions after graceful task cancellation#1991
🛠 Fix: Properly retrieve exceptions after graceful task cancellation#1991gigaverse-oz wants to merge 4 commits into
Conversation
Gather all the tasks output when cancelled. Even asyncio.CancelledError exceptions.
❌ Invalid Changeset Format DetectedOne or more changeset files in this PR have an invalid format. Please ensure they adhere to:
Error details: |
|
Hey, is there a way to easily reproduce this, which plugin were you using? I wonder if it might be more effective to check where we're actually using asyncio.gather. |
|
Hi @theomonnom, I used deepgram, stt. This is the place that have the issue: You create 3 tasks, have only try-finally and use I'd be happy with either solutions as long it can be soon. It litters our logs :-( |
Summary
This PR improves the
gracefully_cancel(now calledcancel_and_wait) function by ensuring that exceptions from cancelled or completed tasks are explicitly retrieved. This preventsasynciofrom logging warnings like:Root Cause
Previously,
gracefully_cancel:.exception()from the tasksWhen
asyncio.gather()is used, it returns a_GatheringFuture, which wraps multiple tasks. If the gathered task is cancelled or raises an exception and that exception is never accessed,asynciologs a warning — even if the tasks are awaited indirectly.Fix
After all futures are awaited, we now iterate over each future:
fut.exception()to mark the exception as retrievedExample
Previously:
Now:
Impact
_GatheringFuturewarnings in normal cancellation flows