From a7a217e60705d9ee21bd2027caa45b91e6e8fd09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=D0=AF=C3=98NE?= <88117897+alvarorichard@users.noreply.github.com> Date: Sat, 29 Aug 2026 08:46:35 -0300 Subject: [PATCH] fix: nil pointer panic when destroying webrtc peer in profileChanged (#695) * This is a no-op with the default configuration: when only a single video pipeline is configured, there is nothing for the stream selector to switch to. The change only has an effect when the operator configures multiple pipelines and enables the bandwidth estimator. * fix(session): guard against nil WebRTC peer in profileChanged" --------- Co-authored-by: alvarorichard --- server/internal/session/session.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/internal/session/session.go b/server/internal/session/session.go index 114233f7..4b4c0a99 100644 --- a/server/internal/session/session.go +++ b/server/internal/session/session.go @@ -51,7 +51,11 @@ func (session *SessionCtx) profileChanged() { // otherwise webrtc destroy would trigger websocket reconnect. In case of kick event, webrtc destroy is called // before websocket destroy that delivers the information about the kick. time.AfterFunc(time.Second, func() { - session.GetWebRTCPeer().Destroy() + // The peer may have been removed if the user disconnected while + // waiting for the delayed teardown. + if webrtcPeer := session.GetWebRTCPeer(); webrtcPeer != nil { + webrtcPeer.Destroy() + } }) }