Browse Source

fix creation and deletion of paths during hot reloading

pull/169/head
aler9 5 years ago
parent
commit
7a3db78de4
  1. 2
      internal/conf/pathconf.go
  2. 8
      internal/pathman/pathman.go
  3. 12
      main_test.go

2
internal/conf/pathconf.go

@ -228,6 +228,6 @@ func (pconf *PathConf) fillAndCheck(name string) error {
// Equal checks whether two PathConfs are equal. // Equal checks whether two PathConfs are equal.
func (pconf *PathConf) Equal(other *PathConf) bool { func (pconf *PathConf) Equal(other *PathConf) bool {
a, _ := json.Marshal(pconf) a, _ := json.Marshal(pconf)
b, _ := json.Marshal(pconf) b, _ := json.Marshal(other)
return string(a) == string(b) return string(a) == string(b)
} }

8
internal/pathman/pathman.go

@ -127,11 +127,7 @@ outer:
// remove paths associated with a conf which doesn't exist anymore // remove paths associated with a conf which doesn't exist anymore
// or has changed // or has changed
for _, pa := range pm.paths { for _, pa := range pm.paths {
if pathConf, ok := pm.pathConfs[pa.ConfName()]; !ok { if pathConf, ok := pm.pathConfs[pa.ConfName()]; !ok || pathConf != pa.Conf() {
delete(pm.paths, pa.Name())
pa.Close()
} else if pathConf != pa.Conf() {
delete(pm.paths, pa.Name()) delete(pm.paths, pa.Name())
pa.Close() pa.Close()
} }
@ -259,7 +255,7 @@ outer:
func (pm *PathManager) createPaths() { func (pm *PathManager) createPaths() {
for pathName, pathConf := range pm.pathConfs { 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, pa := path.New(pm.rtspPort, pm.readTimeout, pm.writeTimeout,
pathName, pathConf, pathName, &pm.wg, pm.stats, pm) pathName, pathConf, pathName, &pm.wg, pm.stats, pm)
pm.paths[pathName] = pa pm.paths[pathName] = pa

12
main_test.go

@ -906,9 +906,14 @@ func TestHotReloading(t *testing.T) {
err := ioutil.WriteFile(confPath, []byte("paths:\n"+ err := ioutil.WriteFile(confPath, []byte("paths:\n"+
" test1:\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) 0644)
require.NoError(t, err) require.NoError(t, err)
defer os.Remove(confPath)
p, err := newProgram([]string{confPath}) p, err := newProgram([]string{confPath})
require.NoError(t, err) require.NoError(t, err)
@ -932,7 +937,10 @@ func TestHotReloading(t *testing.T) {
err = ioutil.WriteFile(confPath, []byte("paths:\n"+ err = ioutil.WriteFile(confPath, []byte("paths:\n"+
" test2:\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) 0644)
require.NoError(t, err) require.NoError(t, err)

Loading…
Cancel
Save