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
+18 -9
View File
@@ -443,16 +443,25 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session) (*webrtc.Sess
ticker := time.NewTicker(rtcpPLIInterval) ticker := time.NewTicker(rtcpPLIInterval)
defer ticker.Stop() defer ticker.Stop()
go func() { //ticker.Stop() does not close channel,so the channel,so the goroutine below needs
for range ticker.C { //its own singal to exit, otherwise it would block on the ticker channel forever and leak memory
err := connection.WriteRTCP([]rtcp.Packet{ done := make(chan struct{})
&rtcp.PictureLossIndication{ defer close(done)
MediaSSRC: uint32(track.SSRC()),
},
})
if err != nil { go func() {
logger.Err(err).Msg("remote track rtcp send err") 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")
}
} }
} }
}() }()