Fix "Task cannot await on itself" when close() runs inside the reader task#534
Open
Nielsh82 wants to merge 1 commit into
Open
Fix "Task cannot await on itself" when close() runs inside the reader task#534Nielsh82 wants to merge 1 commit into
Nielsh82 wants to merge 1 commit into
Conversation
When the Ring server ends a WebRTC session, handle_message() calls close() from within the reader task; _close() then awaits read_task, i.e. the task it is running in, raising "RuntimeError: Task cannot await on itself". Skip awaiting read_task in that case - the websocket has just been closed, so the reader loop exits naturally once handle_message returns. Co-Authored-By: Claude Fable 5 <noreply@anthropic.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.
Description
When the Ring server ends a WebRTC session,
handle_message()(running inside the websocket reader task) ends up callingclose()→_close(), which does:Since this code is already executing inside
read_task, it raises:Observed in the wild through the Home Assistant
ringintegration (ring-doorbell 0.9.14, HA 2026.7.x): every live-view session teardown logs this error, and live views break.Fix
Guard the await with
read_task is not asyncio.current_task(). When_close()is invoked from the reader task itself, awaiting is unnecessary: the websocket has just been closed a few lines above, so theasync forloop terminates and the task completes naturally oncehandle_message()returns.Verified on a live Home Assistant install (HA 2026.7.0, three Ring cameras): with this one-line guard applied, repeated live-view start/stop cycles produce zero
RuntimeErrors where previously every teardown logged one.🤖 Generated with Claude Code
https://claude.ai/code/session_01T7LmwdKV7sFZkcYt6TTMZt