From ca3c507b3f0951c2b468806000c50a8e0e265d5d Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Wed, 5 Nov 2025 17:48:27 +0530 Subject: [PATCH] Prevent invalid track access while peer connection is shutting down. (#4054) --- pkg/rtc/room.go | 1 + pkg/rtc/transport.go | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/rtc/room.go b/pkg/rtc/room.go index ab8f7ebb..e60433d8 100644 --- a/pkg/rtc/room.go +++ b/pkg/rtc/room.go @@ -503,6 +503,7 @@ func (r *Room) Join( fields := append( connectionDetailsFields(infos), "clientInfo", logger.Proto(sutils.ClientInfoWithoutAddress(p.GetClientInfo())), + "connectTime", connectTime, ) p.GetLogger().Infow("participant active", fields...) } else if state == livekit.ParticipantInfo_DISCONNECTED { diff --git a/pkg/rtc/transport.go b/pkg/rtc/transport.go index f8e5b5a0..8004a283 100644 --- a/pkg/rtc/transport.go +++ b/pkg/rtc/transport.go @@ -2905,8 +2905,12 @@ func (t *PCTransport) getMidToTrackIDMapping() map[string]string { transceivers := t.pc.GetTransceivers() midToTrackID := make(map[string]string, len(transceivers)) for _, tr := range transceivers { - if tr.Sender() != nil && tr.Sender().Track() != nil && tr.Mid() != "" { - midToTrackID[tr.Mid()] = tr.Sender().Track().ID() + if mid := tr.Mid(); mid != "" { + if sender := tr.Sender(); sender != nil { + if track := sender.Track(); track != nil { + midToTrackID[mid] = track.ID() + } + } } } return midToTrackID