[#362] node: Cancel ctx in the same routine as for signal watcher
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
parent
df9e099fa7
commit
aabcd8d3e4
2 changed files with 6 additions and 5 deletions
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue