mirror of
https://github.com/bluenviron/mediamtx.git
synced 2025-12-20 02:00:05 -08:00
fix memory leak when reloading the configuration (#4855)
When a path has a MPEG-TS, RTP or WebRTC source and the path configuration is reloaded, a routine was left open because the reload channel was not handled. This fixes the issue.
This commit is contained in:
parent
6d4dfff959
commit
61382e496b
10 changed files with 158 additions and 93 deletions
|
|
@ -2,6 +2,8 @@
|
|||
package webrtc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
|
@ -65,12 +67,12 @@ func (s *Source) Run(params defs.StaticSourceRunParams) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer client.Close() //nolint:errcheck
|
||||
|
||||
var stream *stream.Stream
|
||||
|
||||
medias, err := webrtc.ToStream(client.PeerConnection(), &stream)
|
||||
if err != nil {
|
||||
client.Close() //nolint:errcheck
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -79,6 +81,7 @@ func (s *Source) Run(params defs.StaticSourceRunParams) error {
|
|||
GenerateRTPPackets: true,
|
||||
})
|
||||
if rres.Err != nil {
|
||||
client.Close() //nolint:errcheck
|
||||
return rres.Err
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +91,26 @@ func (s *Source) Run(params defs.StaticSourceRunParams) error {
|
|||
|
||||
client.StartReading()
|
||||
|
||||
return client.Wait(params.Context)
|
||||
readErr := make(chan error)
|
||||
|
||||
go func() {
|
||||
readErr <- client.Wait(context.Background())
|
||||
}()
|
||||
|
||||
for {
|
||||
select {
|
||||
case err = <-readErr:
|
||||
client.Close() //nolint:errcheck
|
||||
return err
|
||||
|
||||
case <-params.ReloadConf:
|
||||
|
||||
case <-params.Context.Done():
|
||||
client.Close() //nolint:errcheck
|
||||
<-readErr
|
||||
return fmt.Errorf("terminated")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// APISourceDescribe implements StaticSource.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue