fix: prevent goroutine leak by adding exit signal for RTCP PLI ticker (#697)

Co-authored-by: alvarorichard <alvarorichard@tuta.io>
This commit is contained in:
KЯØNE
2026-09-10 08:33:49 -03:00
committed by GitHub
parent 347418c3e7
commit 371f5c2c7b
+11 -2
View File
@@ -443,18 +443,27 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session) (*webrtc.Sess
ticker := time.NewTicker(rtcpPLIInterval)
defer ticker.Stop()
//ticker.Stop() does not close channel,so the channel,so the goroutine below needs
//its own singal to exit, otherwise it would block on the ticker channel forever and leak memory
done := make(chan struct{})
defer close(done)
go func() {
for range ticker.C {
for {
select {
case <-done:
return
case <-ticker.C:
err := connection.WriteRTCP([]rtcp.Packet{
&rtcp.PictureLossIndication{
MediaSSRC: uint32(track.SSRC()),
},
})
if err != nil {
logger.Err(err).Msg("remote track rtcp send err")
}
}
}
}()
buf := make([]byte, 1400)