Restrict scope of negotiation time out error logs (#2283)

* Restrict scope of negotiation time out error logs

1. Log "negotiation failed" only if signal channel was active
within half window of negotiation timeout. Negotiation timeout currently
is at 15 seconds. Signal pings are every 10 seconds.
2. In transport.go, do not report negotiation timed out and do not
callback negotiation failure if the peer connection state is not
connected. Goal of negotiation failure tracker is to take remedial
action when an in-session negotiation fails. Seeing a bunch of cases
of the case hitting even without ICE connection forming. Negotiation
timer is not intended for those cases.

* fix test
This commit is contained in:
Raja Subramanian
2023-12-02 12:44:37 +05:30
committed by GitHub
parent dcff75a516
commit d866b5110f
4 changed files with 53 additions and 18 deletions
+1 -1
View File
@@ -2308,7 +2308,7 @@ func (p *ParticipantImpl) onSubscriptionError(trackID livekit.TrackID, fatal boo
} }
func (p *ParticipantImpl) onAnyTransportNegotiationFailed() { func (p *ParticipantImpl) onAnyTransportNegotiationFailed() {
if p.TransportManager.SinceLastSignal() < negotiationFailedTimeout { if p.TransportManager.SinceLastSignal() < negotiationFailedTimeout/2 {
p.params.Logger.Infow("negotiation failed, starting full reconnect") p.params.Logger.Infow("negotiation failed, starting full reconnect")
} }
p.IssueFullReconnect(types.ParticipantCloseReasonNegotiateFailed) p.IssueFullReconnect(types.ParticipantCloseReasonNegotiateFailed)
+10 -4
View File
@@ -390,7 +390,7 @@ func NewPCTransport(params TransportParams) (*PCTransport, error) {
params: params, params: params,
debouncedNegotiate: debounce.New(negotiationFrequency), debouncedNegotiate: debounce.New(negotiationFrequency),
negotiationState: NegotiationStateNone, negotiationState: NegotiationStateNone,
eventCh: make(chan event, 50), eventCh: make(chan event, 100),
previousTrackDescription: make(map[string]*trackDescription), previousTrackDescription: make(map[string]*trackDescription),
canReuseTransceiver: true, canReuseTransceiver: true,
allowedLocalCandidates: utils.NewDedupedSlice[string](maxICECandidates), allowedLocalCandidates: utils.NewDedupedSlice[string](maxICECandidates),
@@ -998,6 +998,12 @@ func (t *PCTransport) OnInitialConnected(f func()) {
t.lock.Lock() t.lock.Lock()
t.onInitialConnected = f t.onInitialConnected = f
t.lock.Unlock() t.lock.Unlock()
if f != nil {
if t.pc.ConnectionState() == webrtc.PeerConnectionStateConnected {
go f()
}
}
} }
func (t *PCTransport) getOnInitialConnected() func() { func (t *PCTransport) getOnInitialConnected() func() {
@@ -1682,7 +1688,7 @@ func (t *PCTransport) setupSignalStateCheckTimer() {
failed := t.negotiationState != NegotiationStateNone failed := t.negotiationState != NegotiationStateNone
if t.negotiateCounter.Load() == negotiateVersion && failed { if t.negotiateCounter.Load() == negotiateVersion && failed && t.pc.ConnectionState() == webrtc.PeerConnectionStateConnected {
t.params.Logger.Infow( t.params.Logger.Infow(
"negotiation timed out", "negotiation timed out",
"localCurrent", t.pc.CurrentLocalDescription(), "localCurrent", t.pc.CurrentLocalDescription(),
@@ -1944,6 +1950,8 @@ func (t *PCTransport) handleRemoteOfferReceived(sd *webrtc.SessionDescription) e
} }
func (t *PCTransport) handleRemoteAnswerReceived(sd *webrtc.SessionDescription) error { func (t *PCTransport) handleRemoteAnswerReceived(sd *webrtc.SessionDescription) error {
t.clearSignalStateCheckTimer()
if err := t.setRemoteDescription(*sd); err != nil { if err := t.setRemoteDescription(*sd); err != nil {
// Pion will call RTPSender.Send method for each new added Downtrack, and return error if the DownTrack.Bind // Pion will call RTPSender.Send method for each new added Downtrack, and return error if the DownTrack.Bind
// returns error. In case of Downtrack.Bind returns ErrUnsupportedCodec, the signal state will be stable as negotiation is aleady compelted // returns error. In case of Downtrack.Bind returns ErrUnsupportedCodec, the signal state will be stable as negotiation is aleady compelted
@@ -1954,8 +1962,6 @@ func (t *PCTransport) handleRemoteAnswerReceived(sd *webrtc.SessionDescription)
} }
} }
t.clearSignalStateCheckTimer()
if t.negotiationState == NegotiationStateRetry { if t.negotiationState == NegotiationStateRetry {
t.setNegotiationState(NegotiationStateNone) t.setNegotiationState(NegotiationStateNone)
+41 -12
View File
@@ -17,6 +17,7 @@ package rtc
import ( import (
"fmt" "fmt"
"strings" "strings"
"sync"
"testing" "testing"
"time" "time"
@@ -38,7 +39,7 @@ func TestMissingAnswerDuringICERestart(t *testing.T) {
} }
transportA, err := NewPCTransport(params) transportA, err := NewPCTransport(params)
require.NoError(t, err) require.NoError(t, err)
_, err = transportA.pc.CreateDataChannel("test", nil) _, err = transportA.pc.CreateDataChannel(ReliableDataChannel, nil)
require.NoError(t, err) require.NoError(t, err)
paramsB := params paramsB := params
@@ -88,7 +89,7 @@ func TestNegotiationTiming(t *testing.T) {
} }
transportA, err := NewPCTransport(params) transportA, err := NewPCTransport(params)
require.NoError(t, err) require.NoError(t, err)
_, err = transportA.pc.CreateDataChannel("test", nil) _, err = transportA.pc.CreateDataChannel(LossyDataChannel, nil)
require.NoError(t, err) require.NoError(t, err)
paramsB := params paramsB := params
@@ -181,7 +182,7 @@ func TestFirstOfferMissedDuringICERestart(t *testing.T) {
} }
transportA, err := NewPCTransport(params) transportA, err := NewPCTransport(params)
require.NoError(t, err) require.NoError(t, err)
_, err = transportA.pc.CreateDataChannel("test", nil) _, err = transportA.pc.CreateDataChannel(ReliableDataChannel, nil)
require.NoError(t, err) require.NoError(t, err)
paramsB := params paramsB := params
@@ -249,7 +250,7 @@ func TestFirstAnswerMissedDuringICERestart(t *testing.T) {
} }
transportA, err := NewPCTransport(params) transportA, err := NewPCTransport(params)
require.NoError(t, err) require.NoError(t, err)
_, err = transportA.pc.CreateDataChannel("test", nil) _, err = transportA.pc.CreateDataChannel(LossyDataChannel, nil)
require.NoError(t, err) require.NoError(t, err)
paramsB := params paramsB := params
@@ -322,15 +323,21 @@ func TestNegotiationFailed(t *testing.T) {
} }
transportA, err := NewPCTransport(params) transportA, err := NewPCTransport(params)
require.NoError(t, err) require.NoError(t, err)
_, err = transportA.pc.CreateDataChannel(ReliableDataChannel, nil)
require.NoError(t, err)
transportA.OnICECandidate(func(candidate *webrtc.ICECandidate) error { paramsB := params
if candidate == nil { paramsB.IsOfferer = false
return nil transportB, err := NewPCTransport(paramsB)
} require.NoError(t, err)
t.Logf("got ICE candidate from A: %v", candidate)
return nil
})
// exchange ICE
handleICEExchange(t, transportA, transportB)
// wait for transport to be connected before maiming the signalling channel
connectTransports(t, transportA, transportB, false, 1, 1)
// reset OnOffer to force a negotiation failure
transportA.OnOffer(func(sd webrtc.SessionDescription) error { return nil }) transportA.OnOffer(func(sd webrtc.SessionDescription) error { return nil })
var failed atomic.Int32 var failed atomic.Int32
transportA.OnNegotiationFailed(func() { transportA.OnNegotiationFailed(func() {
@@ -358,7 +365,7 @@ func TestFilteringCandidates(t *testing.T) {
transport, err := NewPCTransport(params) transport, err := NewPCTransport(params)
require.NoError(t, err) require.NoError(t, err)
_, err = transport.pc.CreateDataChannel("test", nil) _, err = transport.pc.CreateDataChannel(ReliableDataChannel, nil)
require.NoError(t, err) require.NoError(t, err)
_, err = transport.pc.AddTransceiverFromKind(webrtc.RTPCodecTypeAudio) _, err = transport.pc.AddTransceiverFromKind(webrtc.RTPCodecTypeAudio)
@@ -519,6 +526,28 @@ func connectTransports(t *testing.T, offerer, answerer *PCTransport, isICERestar
require.Eventually(t, func() bool { require.Eventually(t, func() bool {
return answerer.pc.ICEConnectionState() == webrtc.ICEConnectionStateConnected return answerer.pc.ICEConnectionState() == webrtc.ICEConnectionStateConnected
}, 10*time.Second, time.Millisecond*10, "answerer did not become connected") }, 10*time.Second, time.Millisecond*10, "answerer did not become connected")
transportsConnected := untilTransportsConnected(offerer, answerer)
transportsConnected.Wait()
}
func untilTransportsConnected(transports ...*PCTransport) *sync.WaitGroup {
var triggered sync.WaitGroup
triggered.Add(len(transports))
for _, t := range transports {
var done atomic.Value
done.Store(false)
hdlr := func() {
if val, ok := done.Load().(bool); ok && !val {
done.Store(true)
triggered.Done()
}
}
t.OnInitialConnected(hdlr)
}
return &triggered
} }
func TestConfigureAudioTransceiver(t *testing.T) { func TestConfigureAudioTransceiver(t *testing.T) {
+1 -1
View File
@@ -555,7 +555,7 @@ func (s *StreamAllocator) postEvent(event Event) {
select { select {
case s.eventCh <- event: case s.eventCh <- event:
default: default:
s.params.Logger.Warnw("stream allocator: event queue full", nil) s.params.Logger.Warnw("stream allocator: event queue full", nil, "event", event.String())
} }
s.eventChMu.RUnlock() s.eventChMu.RUnlock()
} }