fix: suppress ClientConnectionError in frames() generator teardown#4
Open
livepeer-tessa wants to merge 1 commit intomainfrom
Open
fix: suppress ClientConnectionError in frames() generator teardown#4livepeer-tessa wants to merge 1 commit intomainfrom
livepeer-tessa wants to merge 1 commit intomainfrom
Conversation
During session close, the async generator's finally block awaits the producer task which may raise aiohttp.ClientConnectionError when the connection was already dropped. This is expected during teardown but was not suppressed, causing asyncio to log 'Task exception was never retrieved' noise on every clean session close. Add aiohttp.ClientConnectionError to the suppress() context alongside the existing asyncio.CancelledError so teardown-time connection drops are silently discarded. Fixes daydreamlive/scope#897 Signed-off-by: livepeer-tessa <livepeer-tessa@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes daydreamlive/scope#897 — asyncio logs
Task exception was never retrievedon every session close where media output is active.Root Cause
In
MediaOutput.frames(), the async generator'sfinallyblock cancels and awaitsproducer_task. During teardown, that task may raiseaiohttp.ClientConnectionError('Connection closed')because the underlying connection was already dropped when the client disconnected. This error was not suppressed, causing asyncio to log it as an unhandled task exception.Fix
Add
aiohttp.ClientConnectionErrorto thesuppress()context in thefinallyblock, alongside the existingasyncio.CancelledError:Both errors are expected during normal session teardown — the connection being closed is the reason we're tearing down in the first place.
Impact
asyncio - ERROR - Task exception was never retrieved) on every clean session closeaiohttpis already a declared dependency (>=3.9.0), so no new deps addedTesting
The error occurs on every session close with active media output. After this fix, the log line should no longer appear in Grafana/Loki for normal session teardowns (only genuine errors should remain).