From c83376bc00a66a8fd2cc293f63d1c669c9265811 Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Sat, 31 Oct 2026 13:16:19 +0530 Subject: [PATCH] rtc: guard nil source in BroadcastDataMessageForRoom (#5110) Relayed unlabeled data arrives with no local source participant, and the sender identity lookup dereferenced it. Co-authored-by: Claude Opus 5.5 (cherry picked from commit 1681f36610b199797eb7725bf928f7479723e087) --- pkg/rtc/room.go | 12 ++++++++++-- pkg/rtc/room_test.go | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/pkg/rtc/room.go b/pkg/rtc/room.go index a67adf754..39f48560e 100644 --- a/pkg/rtc/room.go +++ b/pkg/rtc/room.go @@ -2180,12 +2180,20 @@ func BroadcastDataPacketForRoom( } func BroadcastDataMessageForRoom(r types.Room, source types.LocalParticipant, data []byte, logger logger.Logger) { + // source is nil for data relayed from a remote node + var sourceID livekit.ParticipantID + var sourceIdentity livekit.ParticipantIdentity + if source != nil { + sourceID = source.ID() + sourceIdentity = source.Identity() + } + utils.ParallelExec(r.GetLocalParticipants(), dataForwardLoadBalanceThreshold, 1, func(op types.LocalParticipant) { - if source != nil && op.ID() == source.ID() { + if source != nil && op.ID() == sourceID { return } - op.SendDataMessageUnlabeled(data, false, source.Identity()) + op.SendDataMessageUnlabeled(data, false, sourceIdentity) }) } diff --git a/pkg/rtc/room_test.go b/pkg/rtc/room_test.go index 3c828ed6b..d844733c6 100644 --- a/pkg/rtc/room_test.go +++ b/pkg/rtc/room_test.go @@ -773,6 +773,21 @@ func TestDataChannel(t *testing.T) { } }) + t.Run("unlabeled broadcast without source", func(t *testing.T) { + rm := newRoomWithParticipants(t, testRoomOpts{num: 2}) + defer rm.Close(types.RoomCloseReasonUnknown) + + BroadcastDataMessageForRoom(rm, nil, []byte("relayed"), rm.logger) + + for _, op := range rm.GetParticipants() { + fp := op.(*typesfakes.FakeLocalParticipant) + require.Equal(t, 1, fp.SendDataMessageUnlabeledCallCount()) + got, _, sender := fp.SendDataMessageUnlabeledArgsForCall(0) + require.Equal(t, []byte("relayed"), got) + require.Empty(t, sender) + } + }) + t.Run("publishing disallowed", func(t *testing.T) { rm := newRoomWithParticipants(t, testRoomOpts{num: 2}) defer rm.Close(types.RoomCloseReasonUnknown)