mirror of
https://github.com/livekit/livekit.git
synced 2026-08-27 22:34:25 +00:00
Do not try to read stats from peer connection after close. (#4002)
Pion does not protect the stats getter and using it after close could cause nil de-reference. Do a couple of things 1. Stop timer that access peer connection stats before closing peer connection. 2. Do not access stats if peer connection is already closed
This commit is contained in:
+12
-5
@@ -688,6 +688,10 @@ func (t *PCTransport) setICEConnectedAt(at time.Time) {
|
||||
}
|
||||
|
||||
func (t *PCTransport) logMayFailedICEStats() {
|
||||
if t.pc.ConnectionState() == webrtc.PeerConnectionStateClosed {
|
||||
return
|
||||
}
|
||||
|
||||
var candidatePairStats []webrtc.ICECandidatePairStats
|
||||
pairStats := t.pc.GetStats()
|
||||
candidateStats := make(map[string]webrtc.ICECandidateStats)
|
||||
@@ -1441,6 +1445,13 @@ func (t *PCTransport) Close() {
|
||||
t.pacer.Stop()
|
||||
}
|
||||
|
||||
t.lock.Lock()
|
||||
if t.mayFailedICEStatsTimer != nil {
|
||||
t.mayFailedICEStatsTimer.Stop()
|
||||
t.mayFailedICEStatsTimer = nil
|
||||
}
|
||||
t.lock.Unlock()
|
||||
|
||||
_ = t.pc.Close()
|
||||
|
||||
t.clearConnTimer()
|
||||
@@ -1460,12 +1471,8 @@ func (t *PCTransport) Close() {
|
||||
dc.Close()
|
||||
}
|
||||
t.unlabeledDataChannels = nil
|
||||
|
||||
if t.mayFailedICEStatsTimer != nil {
|
||||
t.mayFailedICEStatsTimer.Stop()
|
||||
t.mayFailedICEStatsTimer = nil
|
||||
}
|
||||
t.lock.Unlock()
|
||||
|
||||
t.outputAndClearICEStats()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user