Skip to content

KeyError in LiveKit SDK room listener on track_unpublished event #747

Description

@agildav

Describe the bug
When a track_unpublished event is received for a publication that is no longer present in the participant's internal _track_publications map, the SDK raises an unhandled KeyError, which is logged as error running user callback for track_unpublished.

error running user callback for track_unpublished: room_handle: 4
track_unpublished {
  participant_identity: "participant_C7A33F70-..."
  publication_sid: "TR_ACUVxvupEqihta"
}
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/livekit/rtc/room.py", line 560, in _listen_task
    self._on_room_event(event.room_event)
  File "/usr/local/lib/python3.11/site-packages/livekit/rtc/room.py", line 626, in _on_room_event
    rpublication = rparticipant._track_publications.pop(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'TR_ACUVxvupEqihta'

Server
livekit = "^1.0.12"
livekit-agents = "^1.2.18"

  • Environment: EKS
  • any other information about your deployment setup

Client

  • SDK: ios

Origin: LiveKit RTC SDK (livekit/rtc/room.py)

A race condition in the SDK where a track_unpublished event is processed for a publication SID that has already been removed (e.g. participant disconnect / duplicate event). The .pop() call has no default, so a missing key raises KeyError.

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