api, hls, metrics, pprof: always close HTTP listeners

due to a race condition, HTTP listeners could remain open even after
the closure of a component.
This commit is contained in:
aler9 2022-08-30 18:42:29 +02:00
parent 3790af946f
commit f25e14183d
4 changed files with 8 additions and 8 deletions

View file

@ -189,6 +189,7 @@ type api struct {
hlsServer apiHLSServer
parent apiParent
ln net.Listener
mutex sync.Mutex
s *http.Server
}
@ -218,6 +219,7 @@ func newAPI(
rtmpsServer: rtmpsServer,
hlsServer: hlsServer,
parent: parent,
ln: ln,
}
router := gin.New()
@ -268,6 +270,7 @@ func newAPI(
func (a *api) close() {
a.log(logger.Info, "listener is closing")
a.ln.Close() // in case Shutdown() is called before Serve()
a.s.Shutdown(context.Background())
}