From aabcd8d3e42ad7bd8338f48d1e3c8ef0447c344f Mon Sep 17 00:00:00 2001 From: Anton Nikiforov Date: Thu, 18 May 2023 09:28:10 +0300 Subject: [PATCH] [#362] node: Cancel ctx in the same routine as for signal watcher Signed-off-by: Anton Nikiforov --- cmd/frostfs-node/config.go | 2 ++ cmd/frostfs-node/main.go | 9 ++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cmd/frostfs-node/config.go b/cmd/frostfs-node/config.go index 987d27fc..c45d44fd 100644 --- a/cmd/frostfs-node/config.go +++ b/cmd/frostfs-node/config.go @@ -321,6 +321,7 @@ func (a *applicationConfiguration) setGCConfig(newConfig *shardCfg, oldConfig *s // helpers and fields. type internals struct { done chan struct{} + ctxCancel func() internalErr chan error // channel for internal application errors at runtime appCfg *config.Config @@ -1078,6 +1079,7 @@ func (c *cfg) reloadConfig(ctx context.Context) { func (c *cfg) shutdown() { c.setHealthStatus(control.HealthStatus_SHUTTING_DOWN) + c.ctxCancel() c.done <- struct{}{} for i := range c.closers { c.closers[len(c.closers)-1-i].fn() diff --git a/cmd/frostfs-node/main.go b/cmd/frostfs-node/main.go index a2024706..425cf25a 100644 --- a/cmd/frostfs-node/main.go +++ b/cmd/frostfs-node/main.go @@ -57,7 +57,8 @@ func main() { c := initCfg(appCfg) - ctx, cancel := context.WithCancel(context.Background()) + var ctx context.Context + ctx, c.ctxCancel = context.WithCancel(context.Background()) initApp(ctx, c) @@ -67,7 +68,7 @@ func main() { c.setHealthStatus(control.HealthStatus_READY) - wait(c, cancel) + wait(c) } func initAndLog(c *cfg, name string, initializer func(*cfg)) { @@ -140,14 +141,12 @@ func bootUp(ctx context.Context, c *cfg) { startWorkers(ctx, c) } -func wait(c *cfg, cancel func()) { +func wait(c *cfg) { c.log.Info(logs.CommonApplicationStarted, zap.String("version", misc.Version)) <-c.done // graceful shutdown - cancel() - c.log.Debug(logs.FrostFSNodeWaitingForAllProcessesToStop) c.wg.Wait()