From f89d0f68d05870d5aa2d4a9f573eb22d5dcc5ae2 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 31 Aug 2021 18:52:48 -0700 Subject: [PATCH] fix: missing cleanup of tmp folders in NAS gateway setup (#13124) console service should be shutdown last once all shutdown sequences are complete, this is to ensure that we do not prematurely kill the server before it cleans up the `.minio.sys/tmp/uuid` folder. NOTE: this only applies to NAS gateway setup. --- cmd/gateway-main.go | 10 +++------- cmd/globals.go | 3 +++ cmd/notification.go | 3 +++ cmd/server-main.go | 11 ++++------- cmd/signals.go | 4 ++++ 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/cmd/gateway-main.go b/cmd/gateway-main.go index 1089a12ea..b97af7925 100644 --- a/cmd/gateway-main.go +++ b/cmd/gateway-main.go @@ -345,18 +345,14 @@ func StartGateway(ctx *cli.Context, gw Gateway) { } if globalBrowserEnabled { - consoleSrv, err := initConsoleServer() + globalConsoleSrv, err = initConsoleServer() if err != nil { logger.FatalIf(err, "Unable to initialize console service") } go func() { - <-globalOSSignalCh - consoleSrv.Shutdown() + logger.FatalIf(globalConsoleSrv.Serve(), "Unable to initialize console server") }() - - consoleSrv.Serve() - } else { - <-globalOSSignalCh } + <-globalOSSignalCh } diff --git a/cmd/globals.go b/cmd/globals.go index 636da56c0..cd6d05ec0 100644 --- a/cmd/globals.go +++ b/cmd/globals.go @@ -25,6 +25,7 @@ import ( "sync" "time" + "github.com/minio/console/restapi" "github.com/minio/minio-go/v7/pkg/set" "github.com/minio/minio/internal/bucket/bandwidth" "github.com/minio/minio/internal/handlers" @@ -315,6 +316,8 @@ var ( globalTierJournal *tierJournal + globalConsoleSrv *restapi.Server + globalDebugRemoteTiersImmediately []string // Add new variable global values here. ) diff --git a/cmd/notification.go b/cmd/notification.go index 5d4db4a36..8367bdfc2 100644 --- a/cmd/notification.go +++ b/cmd/notification.go @@ -1453,6 +1453,9 @@ func (sys *NotificationSys) GetBandwidthReports(ctx context.Context, buckets ... // GetClusterMetrics - gets the cluster metrics from all nodes excluding self. func (sys *NotificationSys) GetClusterMetrics(ctx context.Context) chan Metric { + if sys == nil { + return nil + } g := errgroup.WithNErrs(len(sys.peerClients)) peerChannels := make([]<-chan Metric, len(sys.peerClients)) for index := range sys.peerClients { diff --git a/cmd/server-main.go b/cmd/server-main.go index 80ce7e96b..bec25f220 100644 --- a/cmd/server-main.go +++ b/cmd/server-main.go @@ -582,20 +582,17 @@ func serverMain(ctx *cli.Context) { } if globalBrowserEnabled { - consoleSrv, err := initConsoleServer() + globalConsoleSrv, err = initConsoleServer() if err != nil { logger.FatalIf(err, "Unable to initialize console service") } go func() { - logger.FatalIf(consoleSrv.Serve(), "Unable to initialize console server") + logger.FatalIf(globalConsoleSrv.Serve(), "Unable to initialize console server") }() - - <-globalOSSignalCh - consoleSrv.Shutdown() - } else { - <-globalOSSignalCh } + + <-globalOSSignalCh } // Initialize object layer with the supplied disks, objectLayer is nil upon any error. diff --git a/cmd/signals.go b/cmd/signals.go index 5f46a0378..e3c03d151 100644 --- a/cmd/signals.go +++ b/cmd/signals.go @@ -66,6 +66,10 @@ func handleSignals() { logger.LogIf(context.Background(), oerr) } + if globalConsoleSrv != nil { + logger.LogIf(context.Background(), globalConsoleSrv.Shutdown()) + } + return (err == nil && oerr == nil) }