Repository navigation
Conversation
… stream creation An ICE candidate arriving before the WebRTC stream is registered (or after it was closed) hard-raised RingError, and callers such as Home Assistant do not catch it, so every early candidate logged a full 'Unknown error' traceback (fixes python-ring-doorbell#560). - generate_webrtc_stream now registers the stream before awaiting generate(), matching generate_async_webrtc_stream; the registration is removed again if generate() raises so no stale stream is left. Early candidates are then held by the stream until the offer is sent (RingWebRtcStream.on_ice_candidate waits for _offered_event). - on_webrtc_candidate now debug-logs and drops candidates for an unknown or closed session instead of raising; there is no stream to deliver them to. Adds regression tests covering the unknown-session, during-generate, and after-close cases, plus the live-stream forwarding control.
The first fix popped the registration only on except Exception, but asyncio.CancelledError inherits BaseException, so cancelling generate_webrtc_stream mid-handshake left the abandoned stream registered: a later candidate would find it and wait on its unset _offered_event until on_ice_candidate timed out after 10s. - Catch BaseException in generate_webrtc_stream (and in the sibling generate_async_webrtc_stream, which had the same stale registration on failure), pop the registration, close the stream so no half-open websocket or reader task is left behind (close() is best-effort here; the original error still propagates), and re-raise so cancellation keeps propagating. - Add cancellation regression tests for both generate paths. (Sol review of fa007bc: CHANGES_REQUESTED, 1 medium finding — this commit addresses it.)
This branch has not been deployed
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.
Fixes #560.
Problem
on_webrtc_candidateraisesRingErrorwhen an ICE candidate arrives before the WebRTC stream is created (or after it closed). In practice this spams Home Assistant logs with tracebacks and drops candidates during the trickle-ICE race.Fix
generate_webrtc_streamnow registers the stream before awaitinggenerate()(matchinggenerate_async_webrtc_stream, which already did this). Early candidates are then held by the stream itself —RingWebRtcStream.on_ice_candidatewaits for_offered_event— so no buffering state was added.on_webrtc_candidatedebug-logs and drops candidates for an unknown or closed session instead of raising, as the issue allows as an alternative to buffering.Tests
tests/test_webrtc.py: 7 tests covering the race (candidate before stream creation, candidate after close, candidate during generation, cancellation cleanup). 3 fail on base, all 7 pass with the fix.ruff check+ruff format --checkclean;mypyclean ondoorbot.py.I used an AI coding assistant for parts of the analysis and test scaffolding; I ran and reviewed the reproduction and the tests myself and reviewed the code before submitting it.