From bf608633118ffe1a8729473f4dcfc44c0ccb7250 Mon Sep 17 00:00:00 2001 From: Denys Smirnov Date: Wed, 19 Nov 2025 16:13:43 +0200 Subject: [PATCH] Fix potential NPE when outbound fails to connect to a room. --- pkg/sip/outbound.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pkg/sip/outbound.go b/pkg/sip/outbound.go index 62107a3b..d4640c25 100644 --- a/pkg/sip/outbound.go +++ b/pkg/sip/outbound.go @@ -306,9 +306,10 @@ func (c *outboundCall) close(err error, status CallStatus, description string, r info.DisconnectReason = reason }) c.media.Close() - _ = c.lkRoom.CloseOutput() - - _ = c.lkRoom.CloseWithReason(status.DisconnectReason()) + if r := c.lkRoom; r != nil { + _ = r.CloseOutput() + _ = r.CloseWithReason(status.DisconnectReason()) + } c.lkRoomIn = nil c.stopSIP(description) @@ -390,6 +391,7 @@ func (c *outboundCall) connectToRoom(ctx context.Context, lkNew RoomConfig, getR lkNew.Participant.Attributes = attrs r := getRoom(c.log, &c.stats.Room) if err := r.Connect(c.c.conf, lkNew); err != nil { + _ = r.Close() return err } // We have to create the track early because we might play a dialtone while SIP connects. @@ -492,6 +494,9 @@ func (c *outboundCall) setStatus(v CallStatus) { if attr == "" { return } + if c.lkRoom == nil { + return + } r := c.lkRoom.Room() if r == nil { return @@ -617,6 +622,9 @@ func (c *outboundCall) sipSignal(ctx context.Context, tid traceid.ID) error { } func (c *outboundCall) handleDTMF(ev dtmf.Event) { + if c.lkRoom == nil { + return + } _ = c.lkRoom.SendData(&livekit.SipDTMF{ Code: uint32(ev.Code), Digit: string([]byte{ev.Digit}),