diff --git a/internal/core/api.go b/internal/core/api.go index 3fc623d3..bd9d6bfd 100644 --- a/internal/core/api.go +++ b/internal/core/api.go @@ -270,8 +270,8 @@ 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()) + a.ln.Close() // in case Shutdown() is called before Serve() } func (a *api) log(level logger.Level, format string, args ...interface{}) { diff --git a/internal/core/api_test.go b/internal/core/api_test.go index 2ff80924..1ec037dd 100644 --- a/internal/core/api_test.go +++ b/internal/core/api_test.go @@ -60,6 +60,10 @@ func httpRequest(method string, ur string, in interface{}, out interface{}) erro } func TestAPIConfigGet(t *testing.T) { + // since the HTTP server is created and deleted multiple times, + // we can't reuse TCP connections. + http.DefaultTransport.(*http.Transport).DisableKeepAlives = true + p, ok := newInstance("api: yes\n") require.Equal(t, true, ok) defer p.close() diff --git a/internal/core/hls_server.go b/internal/core/hls_server.go index 9b79bdae..e717ac1f 100644 --- a/internal/core/hls_server.go +++ b/internal/core/hls_server.go @@ -248,8 +248,8 @@ outer: s.ctxCancel() - s.ln.Close() // in case Shutdown() is called before Serve() hs.Shutdown(context.Background()) + s.ln.Close() // in case Shutdown() is called before Serve() s.pathManager.hlsServerSet(nil) diff --git a/internal/core/metrics.go b/internal/core/metrics.go index ad84ba90..fc1a771b 100644 --- a/internal/core/metrics.go +++ b/internal/core/metrics.go @@ -72,25 +72,21 @@ func newMetrics( m.log(logger.Info, "listener opened on "+address) - go m.run() + go m.server.Serve(m.ln) return m, nil } 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()) + m.ln.Close() // in case Shutdown() is called before Serve() } func (m *metrics) log(level logger.Level, format string, args ...interface{}) { m.parent.Log(level, "[metrics] "+format, args...) } -func (m *metrics) run() { - m.server.Serve(m.ln) -} - func (m *metrics) onMetrics(ctx *gin.Context) { out := "" diff --git a/internal/core/pprof.go b/internal/core/pprof.go index 1e8148b9..7b36dbfc 100644 --- a/internal/core/pprof.go +++ b/internal/core/pprof.go @@ -42,21 +42,17 @@ func newPPROF( pp.log(logger.Info, "listener opened on "+address) - go pp.run() + go pp.server.Serve(pp.ln) return pp, nil } 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()) + pp.ln.Close() // in case Shutdown() is called before Serve() } func (pp *pprof) log(level logger.Level, format string, args ...interface{}) { pp.parent.Log(level, "[pprof] "+format, args...) } - -func (pp *pprof) run() { - pp.server.Serve(pp.ln) -}