Log errors on sending offer/answer (#933)

* Log errors on sending offer/answer

* minor clean up

* remove unneeded logs

* fix test
This commit is contained in:
Raja Subramanian
2022-08-19 17:54:27 +05:30
committed by GitHub
parent e4e2e4189b
commit fae3857800
3 changed files with 39 additions and 31 deletions
+3 -4
View File
@@ -485,6 +485,7 @@ func (p *ParticipantImpl) onPublisherAnswer(answer webrtc.SessionDescription) {
prometheus.ServiceOperationCounter.WithLabelValues("answer", "error", "write_message").Add(1) prometheus.ServiceOperationCounter.WithLabelValues("answer", "error", "write_message").Add(1)
return return
} }
prometheus.ServiceOperationCounter.WithLabelValues("answer", "success", "").Add(1)
p.TransportManager.PublisherLocalDescriptionSent() p.TransportManager.PublisherLocalDescriptionSent()
if p.isPublisher.Load() != p.CanPublish() { if p.isPublisher.Load() != p.CanPublish() {
@@ -501,8 +502,6 @@ func (p *ParticipantImpl) onPublisherAnswer(answer webrtc.SessionDescription) {
} }
} }
prometheus.ServiceOperationCounter.WithLabelValues("answer", "success", "").Add(1)
if p.MigrateState() == types.MigrateStateSync { if p.MigrateState() == types.MigrateStateSync {
go p.handleMigrateMutedTrack() go p.handleMigrateMutedTrack()
} }
@@ -1076,9 +1075,9 @@ func (p *ParticipantImpl) onSubscriberOffer(offer webrtc.SessionDescription) {
}) })
if err != nil { if err != nil {
prometheus.ServiceOperationCounter.WithLabelValues("offer", "error", "write_message").Add(1) prometheus.ServiceOperationCounter.WithLabelValues("offer", "error", "write_message").Add(1)
} else { return
prometheus.ServiceOperationCounter.WithLabelValues("offer", "success", "").Add(1)
} }
prometheus.ServiceOperationCounter.WithLabelValues("offer", "success", "").Add(1)
p.TransportManager.SubscriberLocalDescriptionSent() p.TransportManager.SubscriberLocalDescriptionSent()
} }
+35 -26
View File
@@ -36,7 +36,7 @@ const (
ReliableDataChannel = "_reliable" ReliableDataChannel = "_reliable"
negotiationFrequency = 150 * time.Millisecond negotiationFrequency = 150 * time.Millisecond
negotiationFailedTimout = 15 * time.Second negotiationFailedTimeout = 15 * time.Second
dtlsRetransmissionInterval = 100 * time.Millisecond dtlsRetransmissionInterval = 100 * time.Millisecond
iceDisconnectedTimeout = 10 * time.Second // compatible for ice-lite with firefox client iceDisconnectedTimeout = 10 * time.Second // compatible for ice-lite with firefox client
@@ -718,12 +718,7 @@ func (t *PCTransport) SendDataPacket(dp *livekit.DataPacket) error {
} }
func (t *PCTransport) Close() { func (t *PCTransport) Close() {
t.lock.Lock() t.clearSignalStateCheckTimer()
if t.signalStateCheckTimer != nil {
t.signalStateCheckTimer.Stop()
t.signalStateCheckTimer = nil
}
t.lock.Unlock()
if t.streamAllocator != nil { if t.streamAllocator != nil {
t.streamAllocator.Stop() t.streamAllocator.Stop()
@@ -781,10 +776,7 @@ func (t *PCTransport) SetRemoteDescription(sd webrtc.SessionDescription) error {
lastState := t.negotiationState lastState := t.negotiationState
t.negotiationState = negotiationStateNone t.negotiationState = negotiationStateNone
if t.signalStateCheckTimer != nil { t.clearSignalStateCheckTimerLocked()
t.signalStateCheckTimer.Stop()
t.signalStateCheckTimer = nil
}
for _, c := range t.pendingRemoteCandidates { for _, c := range t.pendingRemoteCandidates {
if err := t.pc.AddICECandidate(c); err != nil { if err := t.pc.AddICECandidate(c); err != nil {
@@ -1018,6 +1010,37 @@ func (t *PCTransport) CreateAndSendAnswer(enableDTX bool) error {
return nil return nil
} }
func (t *PCTransport) clearSignalStateCheckTimer() {
t.lock.Lock()
t.clearSignalStateCheckTimerLocked()
t.lock.Unlock()
}
func (t *PCTransport) clearSignalStateCheckTimerLocked() {
if t.signalStateCheckTimer != nil {
t.signalStateCheckTimer.Stop()
t.signalStateCheckTimer = nil
}
}
func (t *PCTransport) setupSignalStateCheckTimerLocked() {
negotiateVersion := t.negotiateCounter.Inc()
t.clearSignalStateCheckTimerLocked()
t.signalStateCheckTimer = time.AfterFunc(negotiationFailedTimeout, func() {
t.lock.Lock()
t.clearSignalStateCheckTimerLocked()
failed := t.negotiationState != negotiationStateNone
t.lock.Unlock()
if t.negotiateCounter.Load() == negotiateVersion && failed {
if t.onNegotiationFailed != nil {
t.onNegotiationFailed()
}
}
})
}
func (t *PCTransport) CreateAndSendOffer(options *webrtc.OfferOptions) error { func (t *PCTransport) CreateAndSendOffer(options *webrtc.OfferOptions) error {
t.lock.Lock() t.lock.Lock()
defer t.lock.Unlock() defer t.lock.Unlock()
@@ -1136,21 +1159,7 @@ func (t *PCTransport) createAndSendOffer(options *webrtc.OfferOptions) error {
t.restartAfterGathering = false t.restartAfterGathering = false
t.negotiationPending = make(map[livekit.ParticipantID]bool) t.negotiationPending = make(map[livekit.ParticipantID]bool)
negotiateVersion := t.negotiateCounter.Inc() t.setupSignalStateCheckTimerLocked()
if t.signalStateCheckTimer != nil {
t.signalStateCheckTimer.Stop()
t.signalStateCheckTimer = nil
}
t.signalStateCheckTimer = time.AfterFunc(negotiationFailedTimout, func() {
t.lock.RLock()
failed := t.negotiationState != negotiationStateNone
t.lock.RUnlock()
if t.negotiateCounter.Load() == negotiateVersion && failed {
if t.onNegotiationFailed != nil {
t.onNegotiationFailed()
}
}
})
go t.onOffer(offer) go t.onOffer(offer)
return nil return nil
+1 -1
View File
@@ -268,7 +268,7 @@ func TestNegotiationFailed(t *testing.T) {
transportA.CreateAndSendOffer(nil) transportA.CreateAndSendOffer(nil)
require.Eventually(t, func() bool { require.Eventually(t, func() bool {
return atomic.LoadInt32(&failed) == 1 return atomic.LoadInt32(&failed) == 1
}, negotiationFailedTimout+time.Second, 10*time.Millisecond, "negotiation failed") }, negotiationFailedTimeout+time.Second, 10*time.Millisecond, "negotiation failed")
} }
func TestFilteringCandidates(t *testing.T) { func TestFilteringCandidates(t *testing.T) {