From cbb2c1d3bdd8d7c6c5929f0d7bfe99e987783b4e Mon Sep 17 00:00:00 2001 From: Sam Kleinman Date: Thu, 17 Feb 2022 08:07:44 -0500 Subject: [PATCH] node: allow orderly shutdown if context is canceled and gensis is in the future (#7817) --- node/node.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/node/node.go b/node/node.go index 62cc2c74f..b2020829c 100644 --- a/node/node.go +++ b/node/node.go @@ -441,7 +441,14 @@ func (n *nodeImpl) OnStart(ctx context.Context) error { genTime := n.genesisDoc.GenesisTime if genTime.After(now) { n.logger.Info("Genesis time is in the future. Sleeping until then...", "genTime", genTime) - time.Sleep(genTime.Sub(now)) + + timer := time.NewTimer(genTime.Sub(now)) + defer timer.Stop() + select { + case <-ctx.Done(): + return ctx.Err() + case <-timer.C: + } } // Start the RPC server before the P2P server