Skip to content

on_webrtc_candidate raises RingError when an ICE candidate arrives before the stream is created (trickle-ICE race) #560

Open

Description

@rlnicoli-ai

The problem

When a Home Assistant frontend opens a Ring live view, ICE candidates are delivered to the library as separate websocket messages (HA camera/webrtc ws_candidate → Ring async_on_webrtc_candidate → RingDoorBell.on_webrtc_candidate). If a candidate arrives before the offer has been processed — i.e. the session is not yet in self._webrtc_streams — on_webrtc_candidate hard-raises:

if stream := self._webrtc_streams.get(session_id):
    await stream.on_ice_candidate(candidate, multi_line_index)
else:
    msg = "Ice candidate received before stream has been created."
    raise RingError(msg)

The candidate is discarded, and because HA's ring/camera.py does not catch RingError there, every early candidate produces a full "Unknown error" traceback in the HA log (homeassistant.components.websocket_api.http.connection). Bursts of 4–5+ occur at live-view start.

The same can happen for a candidate that arrives after a session was closed and popped from _webrtc_streams.

Impact

Streams still connect in the observed cases (later candidates succeed once registration lands), so this is primarily log noise plus lost candidates. In pathological timing — all of a client's candidates beating the offer — a connection attempt could fail and need a retry.

Environment

  • python-ring-doorbell 0.9.14 (latest release; the same raise is present on master)
  • Home Assistant 2026.10.0 (Ring integration)
  • Client: Home Assistant iOS app (WebRTC viewer)
  • Observed repeatedly on 2026-10-16 and 2026-10-17, each time while a Ring camera live view was opened from the iOS app

Traceback (from HA core log)

File "/usr/src/homeassistant/homeassistant/components/camera/webrtc.py", line 347, in ws_candidate
    await camera.async_on_webrtc_candidate(msg["session_id"], msg["candidate"])
File "/usr/src/homeassistant/homeassistant/components/ring/camera.py", line 242, in async_on_webrtc_candidate
    await self._device.on_webrtc_candidate(...)
ring_doorbell.exceptions.RingError: Ice candidate received before stream has been created.

Suggested fix

Buffer candidates per session_id until the stream registers (flush on creation, drop on close), or downgrade this case to a debug/warning log and drop the candidate instead of raising. Either removes the traceback spam; buffering additionally removes the candidate-loss race introduced with trickle ICE (#460).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions