mirror of
https://github.com/bluenviron/mediamtx
synced 2025-03-06 04:17:53 +00:00
fix creation and deletion of paths during hot reloading
This commit is contained in:
parent
b1153bbcb4
commit
7a3db78de4
@ -228,6 +228,6 @@ func (pconf *PathConf) fillAndCheck(name string) error {
|
||||
// Equal checks whether two PathConfs are equal.
|
||||
func (pconf *PathConf) Equal(other *PathConf) bool {
|
||||
a, _ := json.Marshal(pconf)
|
||||
b, _ := json.Marshal(pconf)
|
||||
b, _ := json.Marshal(other)
|
||||
return string(a) == string(b)
|
||||
}
|
||||
|
@ -127,11 +127,7 @@ outer:
|
||||
// remove paths associated with a conf which doesn't exist anymore
|
||||
// or has changed
|
||||
for _, pa := range pm.paths {
|
||||
if pathConf, ok := pm.pathConfs[pa.ConfName()]; !ok {
|
||||
delete(pm.paths, pa.Name())
|
||||
pa.Close()
|
||||
|
||||
} else if pathConf != pa.Conf() {
|
||||
if pathConf, ok := pm.pathConfs[pa.ConfName()]; !ok || pathConf != pa.Conf() {
|
||||
delete(pm.paths, pa.Name())
|
||||
pa.Close()
|
||||
}
|
||||
@ -259,7 +255,7 @@ outer:
|
||||
|
||||
func (pm *PathManager) createPaths() {
|
||||
for pathName, pathConf := range pm.pathConfs {
|
||||
if pathConf.Regexp == nil {
|
||||
if _, ok := pm.paths[pathName]; !ok && pathConf.Regexp == nil {
|
||||
pa := path.New(pm.rtspPort, pm.readTimeout, pm.writeTimeout,
|
||||
pathName, pathConf, pathName, &pm.wg, pm.stats, pm)
|
||||
pm.paths[pathName] = pa
|
||||
|
12
main_test.go
12
main_test.go
@ -906,9 +906,14 @@ func TestHotReloading(t *testing.T) {
|
||||
|
||||
err := ioutil.WriteFile(confPath, []byte("paths:\n"+
|
||||
" test1:\n"+
|
||||
" runOnDemand: ffmpeg -hide_banner -loglevel error -re -i testimages/ffmpeg/emptyvideo.ts -c copy -f rtsp rtsp://localhost:$RTSP_PORT/$RTSP_PATH\n"),
|
||||
" runOnDemand: ffmpeg -hide_banner -loglevel error -re -i testimages/ffmpeg/emptyvideo.ts -c copy -f rtsp rtsp://localhost:$RTSP_PORT/$RTSP_PATH\n"+
|
||||
" test3:\n"+
|
||||
" runOnInit: echo aaa\n"+
|
||||
" test4:\n"+
|
||||
" runOnInit: echo bbb\n"),
|
||||
0644)
|
||||
require.NoError(t, err)
|
||||
defer os.Remove(confPath)
|
||||
|
||||
p, err := newProgram([]string{confPath})
|
||||
require.NoError(t, err)
|
||||
@ -932,7 +937,10 @@ func TestHotReloading(t *testing.T) {
|
||||
|
||||
err = ioutil.WriteFile(confPath, []byte("paths:\n"+
|
||||
" test2:\n"+
|
||||
" runOnDemand: ffmpeg -hide_banner -loglevel error -re -i testimages/ffmpeg/emptyvideo.ts -c copy -f rtsp rtsp://localhost:$RTSP_PORT/$RTSP_PATH\n"),
|
||||
" runOnDemand: ffmpeg -hide_banner -loglevel error -re -i testimages/ffmpeg/emptyvideo.ts -c copy -f rtsp rtsp://localhost:$RTSP_PORT/$RTSP_PATH\n"+
|
||||
" test3:\n"+
|
||||
" test4:\n"+
|
||||
" runOnInit: echo bbb\n"),
|
||||
0644)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user