From a8965cdec746d1ddbb636cda0ad6b86e136c7209 Mon Sep 17 00:00:00 2001 From: Ingo Oppermann Date: Tue, 4 Jul 2023 12:35:08 +0200 Subject: [PATCH] Change core shutdown sequence Now the cluster, restreamer (processes), and the servers (HTTP, HTTP, RTMP, SRT) are shutdown first, then any other services. Before, e.g. the session collector was closed very early before the servers. This would have lead to loss of a few sessions. --- app/api/api.go | 91 +++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 46 deletions(-) diff --git a/app/api/api.go b/app/api/api.go index 7a013db9..69db9088 100644 --- a/app/api/api.go +++ b/app/api/api.go @@ -1734,20 +1734,6 @@ func (a *api) stop() { a.cluster.Shutdown() } - if a.iam != nil { - a.iam.Close() - } - - if a.update != nil { - a.update.Stop() - a.update = nil - } - - if a.service != nil { - a.service.Stop() - a.service = nil - } - // Stop all restream processes if a.restream != nil { logger.Info().Log("Stopping all processes ...") @@ -1755,38 +1741,6 @@ func (a *api) stop() { a.restream = nil } - if a.process != nil { - a.process.Stop() - a.process = nil - } - - // Stop the session tracker - if a.sessions != nil { - a.sessions.UnregisterAll() - a.sessions.Close() - a.sessions = nil - } - - // Unregister all collectors - if a.metrics != nil { - a.metrics.UnregisterAll() - a.metrics = nil - } - - if a.prom != nil { - a.prom.UnregisterAll() - a.prom = nil - } - - // Free the cached objects - if a.cache != nil { - a.cache.Purge() - a.cache = nil - } - - // Free the S3 mounts - a.s3fs = map[string]fs.Filesystem{} - // Stop the SRT server if a.srtserver != nil { a.log.logger.srt.Info().Log("Stopping ...") @@ -1835,11 +1789,56 @@ func (a *api) stop() { a.sidecarserver = nil } + if a.iam != nil { + a.iam.Close() + } + + if a.update != nil { + a.update.Stop() + a.update = nil + } + + if a.service != nil { + a.service.Stop() + a.service = nil + } + + if a.process != nil { + a.process.Stop() + a.process = nil + } + + // Unregister all collectors + if a.metrics != nil { + a.metrics.UnregisterAll() + a.metrics = nil + } + + if a.prom != nil { + a.prom.UnregisterAll() + a.prom = nil + } + + // Free the cached objects + if a.cache != nil { + a.cache.Purge() + a.cache = nil + } + + // Free the S3 mounts + a.s3fs = map[string]fs.Filesystem{} + // Stop resource observer if a.resources != nil { a.resources.Stop() } + // Stop the session tracker + if a.sessions != nil { + a.sessions.Close() + a.sessions = nil + } + // Stop the GC ticker if a.gcTickerStop != nil { a.gcTickerStop()