From 47ba2809a054801d582867b24021ba8a72d2e76c Mon Sep 17 00:00:00 2001 From: Jernej Kos Date: Fri, 5 Jun 2020 11:08:39 +0200 Subject: [PATCH] go/consensus/tendermint: Don't panic on context cancellation --- .changelog/2982.bugfix.md | 1 + go/consensus/tendermint/tendermint.go | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 .changelog/2982.bugfix.md diff --git a/.changelog/2982.bugfix.md b/.changelog/2982.bugfix.md new file mode 100644 index 00000000000..4000ae7a616 --- /dev/null +++ b/.changelog/2982.bugfix.md @@ -0,0 +1 @@ +go/consensus/tendermint: Don't panic on context cancellation diff --git a/go/consensus/tendermint/tendermint.go b/go/consensus/tendermint/tendermint.go index e1040601758..f58f148c07c 100644 --- a/go/consensus/tendermint/tendermint.go +++ b/go/consensus/tendermint/tendermint.go @@ -162,7 +162,7 @@ func (m *failMonitor) markCleanShutdown() { m.isCleanShutdown = true } -func newFailMonitor(logger *logging.Logger, fn func()) *failMonitor { +func newFailMonitor(ctx context.Context, logger *logging.Logger, fn func()) *failMonitor { // Tendermint in it's infinite wisdom, doesn't terminate when // consensus fails, instead opting to "just" log, and tear down // the ConsensusState. Since this behavior is stupid, watch for @@ -178,7 +178,7 @@ func newFailMonitor(logger *logging.Logger, fn func()) *failMonitor { m.Lock() defer m.Unlock() - if !m.isCleanShutdown { + if !m.isCleanShutdown && ctx.Err() == nil { logger.Error("unexpected termination detected") panic("tendermint: unexpected termination detected, consensus failure?") } @@ -1150,7 +1150,7 @@ func (t *tendermintService) lazyInit() error { return fmt.Errorf("tendermint: internal error: state database not set") } t.client = tmcli.New(t.node) - t.failMonitor = newFailMonitor(t.Logger, t.node.ConsensusState().Wait) + t.failMonitor = newFailMonitor(t.ctx, t.Logger, t.node.ConsensusState().Wait) return nil }