Skip to content

avoid KeyError when track is already unpublished#743

Merged
davidzhao merged 5 commits into
mainfrom
dz/fix-track-error
Jul 3, 2026
Merged

avoid KeyError when track is already unpublished#743
davidzhao merged 5 commits into
mainfrom
dz/fix-track-error

Conversation

@davidzhao

Copy link
Copy Markdown
Member

fixes #4639

@davidzhao davidzhao requested a review from a team July 3, 2026 18:55

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

Open in Devin Review

Comment on lines 840 to 842
elif which == "track_subscribed":
owned_track_info = event.track_subscribed.track
track_info = owned_track_info.info

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚩 Other remote-track event handlers still use hard dictionary lookups and may crash under the same race conditions

This PR defensively handles the case where track_unpublished arrives after the participant or publication has already been removed. However, the same race condition (participant disconnected before event is processed) could affect track_unsubscribed (room.py:857-858), track_subscribed (room.py:843-844), track_subscription_failed (room.py:867-868), track_muted (room.py:879), and track_unmuted (room.py:890), all of which still use hard [] lookups on self._remote_participants and track_publications. If the fix here is warranted, the same defensive pattern may be needed in those handlers to avoid KeyError crashes in _listen_task.

(Refers to lines 840-865)

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

devin-ai-integration[bot]

This comment was marked as resolved.

Comment thread livekit-rtc/livekit/rtc/room.py Outdated
@davidzhao davidzhao merged commit a9a28f0 into main Jul 3, 2026
30 checks passed
@davidzhao davidzhao deleted the dz/fix-track-error branch July 3, 2026 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants