mirror of
https://github.com/m1k1o/neko.git
synced 2026-11-03 00:11:48 -06:00
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:
@@ -443,18 +443,27 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session) (*webrtc.Sess
|
|||||||
ticker := time.NewTicker(rtcpPLIInterval)
|
ticker := time.NewTicker(rtcpPLIInterval)
|
||||||
defer ticker.Stop()
|
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() {
|
go func() {
|
||||||
for range ticker.C {
|
for {
|
||||||
|
select {
|
||||||
|
case <-done:
|
||||||
|
return
|
||||||
|
case <-ticker.C:
|
||||||
err := connection.WriteRTCP([]rtcp.Packet{
|
err := connection.WriteRTCP([]rtcp.Packet{
|
||||||
&rtcp.PictureLossIndication{
|
&rtcp.PictureLossIndication{
|
||||||
MediaSSRC: uint32(track.SSRC()),
|
MediaSSRC: uint32(track.SSRC()),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Err(err).Msg("remote track rtcp send err")
|
logger.Err(err).Msg("remote track rtcp send err")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
buf := make([]byte, 1400)
|
buf := make([]byte, 1400)
|
||||||
|
|||||||
Reference in New Issue
Block a user