From 704449247e45b53444bed3ca57bbbd955ee6a7d6 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Mon, 27 Oct 2025 13:03:03 +0000 Subject: [PATCH] if RingingTimeout is provided, deadline should be set to that timeout. (#4018) * if RingingTimeout is provided, deadline should be set to that timeout. This is because the SIP bridge will not return until RingingTimeout which may be longer than the 30 second default deadline. * handle Deadline being "before" timeout. --- pkg/service/sip.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/service/sip.go b/pkg/service/sip.go index 0ce3c9c15..cb81a0030 100644 --- a/pkg/service/sip.go +++ b/pkg/service/sip.go @@ -657,9 +657,22 @@ func (s *SIPService) TransferSIPParticipant(ctx context.Context, req *livekit.Tr return nil, err } + // by default we set the timeout to be 30 seconds. + // this timeout covers: + // - a network failure between this process and the LiveKit SIP bridge + // - the SIP transfer target not returning 200 OK fast enough. + // WARN: any timeout/cancellation of a SIP transfer risks leaving + // either the SIP bridge, or the SIP REFER exchange, in a "unknown" state. timeout := 30 * time.Second + if req.RingingTimeout != nil { + timeout = req.RingingTimeout.AsDuration() + } + + // it's also possible the ctx has a Deadline. + // in that case we want to use that deadline, + // or our timeout, whichover is soonest. if deadline, ok := ctx.Deadline(); ok { - timeout = time.Until(deadline) + timeout = min(timeout, time.Until(deadline)) } else { var cancel func() ctx, cancel = context.WithTimeout(ctx, timeout)