mirror of
https://github.com/bluenviron/mediamtx
synced 2024-12-14 18:54:54 +00:00
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:
parent
3790af946f
commit
f25e14183d
@ -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())
|
||||
}
|
||||
|
||||
|
@ -248,6 +248,7 @@ outer:
|
||||
|
||||
s.ctxCancel()
|
||||
|
||||
s.ln.Close() // in case Shutdown() is called before Serve()
|
||||
hs.Shutdown(context.Background())
|
||||
|
||||
s.pathManager.hlsServerSet(nil)
|
||||
|
@ -79,6 +79,7 @@ func newMetrics(
|
||||
|
||||
func (m *metrics) close() {
|
||||
m.log(logger.Info, "listener is closing")
|
||||
m.ln.Close() // in case Shutdown() is called before Serve()
|
||||
m.server.Shutdown(context.Background())
|
||||
}
|
||||
|
||||
@ -87,10 +88,7 @@ func (m *metrics) log(level logger.Level, format string, args ...interface{}) {
|
||||
}
|
||||
|
||||
func (m *metrics) run() {
|
||||
err := m.server.Serve(m.ln)
|
||||
if err != http.ErrServerClosed {
|
||||
panic(err)
|
||||
}
|
||||
m.server.Serve(m.ln)
|
||||
}
|
||||
|
||||
func (m *metrics) onMetrics(ctx *gin.Context) {
|
||||
|
@ -49,6 +49,7 @@ func newPPROF(
|
||||
|
||||
func (pp *pprof) close() {
|
||||
pp.log(logger.Info, "listener is closing")
|
||||
pp.ln.Close() // in case Shutdown() is called before Serve()
|
||||
pp.server.Shutdown(context.Background())
|
||||
}
|
||||
|
||||
@ -57,8 +58,5 @@ func (pp *pprof) log(level logger.Level, format string, args ...interface{}) {
|
||||
}
|
||||
|
||||
func (pp *pprof) run() {
|
||||
err := pp.server.Serve(pp.ln)
|
||||
if err != http.ErrServerClosed {
|
||||
panic(err)
|
||||
}
|
||||
pp.server.Serve(pp.ln)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user