Skip to content

Commit

Permalink
go/consensus/tendermint: Don't panic on context cancellation
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Jun 5, 2020
1 parent dff6edc commit 1d40815
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions go/consensus/tendermint/tendermint.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ var (
type failMonitor struct {
sync.Mutex

ctx context.Context
isCleanShutdown bool
}

Expand All @@ -162,7 +163,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
Expand All @@ -178,7 +179,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?")
}
Expand Down Expand Up @@ -1150,7 +1151,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
}
Expand Down

0 comments on commit 1d40815

Please sign in to comment.