From d7f7c068560f75597d6535dc3b95f905095af5a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ecl=C3=A9sio=20Junior?= Date: Fri, 10 Mar 2023 11:37:16 -0400 Subject: [PATCH] fix(lib/grandpa): ensure `finalisationEngine` exits when stop channel is triggered (#3141) Signed-off-by: dependabot[bot] Co-authored-by: Quentin McGaw --- lib/grandpa/finalisation.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/grandpa/finalisation.go b/lib/grandpa/finalisation.go index e6684951c5..5193e9da0b 100644 --- a/lib/grandpa/finalisation.go +++ b/lib/grandpa/finalisation.go @@ -344,11 +344,15 @@ func (f *finalisationEngine) Stop() (err error) { return nil } +var errFinalisationEngineStopped = errors.New("finalisation engine stopped") + func (f *finalisationEngine) Run() (err error) { defer close(f.engineDone) err = f.defineRoundVotes() - if err != nil { + if errors.Is(err, errFinalisationEngineStopped) { + return nil + } else if err != nil { return fmt.Errorf("defining round votes: %w", err) } @@ -360,7 +364,7 @@ func (f *finalisationEngine) Run() (err error) { return nil } -func (f *finalisationEngine) defineRoundVotes() error { +func (f *finalisationEngine) defineRoundVotes() (err error) { gossipInterval := f.grandpaService.interval determinePrevoteTimer := time.NewTimer(2 * gossipInterval) determinePrecommitTimer := time.NewTimer(4 * gossipInterval) @@ -372,7 +376,7 @@ func (f *finalisationEngine) defineRoundVotes() error { case <-f.stopCh: determinePrevoteTimer.Stop() determinePrecommitTimer.Stop() - return nil + return fmt.Errorf("%w", errFinalisationEngineStopped) case <-determinePrevoteTimer.C: alreadyCompletable, err := f.grandpaService.checkRoundCompletable()