From 7a3db78de4a1335cdf2431e2269d3b9fbb23f849 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Sun, 8 Nov 2020 22:07:15 +0100 Subject: [PATCH] fix creation and deletion of paths during hot reloading --- internal/conf/pathconf.go | 2 +- internal/pathman/pathman.go | 8 ++------ main_test.go | 12 ++++++++++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/internal/conf/pathconf.go b/internal/conf/pathconf.go index 12eb3e1f..caeb5cb7 100644 --- a/internal/conf/pathconf.go +++ b/internal/conf/pathconf.go @@ -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) } diff --git a/internal/pathman/pathman.go b/internal/pathman/pathman.go index 25e6b223..e92805a7 100644 --- a/internal/pathman/pathman.go +++ b/internal/pathman/pathman.go @@ -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 diff --git a/main_test.go b/main_test.go index 323a8470..f1f4b34e 100644 --- a/main_test.go +++ b/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)