Skip to content

Commit

Permalink
core/consensus: add leak debug logs (#2441)
Browse files Browse the repository at this point in the history
Add debug logs to troubleshoot goroutine leak.

category: misc
ticket: none
  • Loading branch information
corverroos authored Jul 17, 2023
1 parent c74cc8a commit 63b59f3
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions core/consensus/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ func (c *Component) ProposePriority(ctx context.Context, duty core.Duty, msg *pb
// It either runs the consensus instance if it is not already running or
// waits until it completes, in both cases it returns the resulting error.
func (c *Component) propose(ctx context.Context, duty core.Duty, value proto.Message) error {
// TODO(corver): Remove debug log before v0.17 release.
log.Debug(ctx, "Consensus proposed", z.Any("duty", duty))

hash, err := hashProto(value)
if err != nil {
return err
Expand Down Expand Up @@ -332,6 +335,9 @@ func (c *Component) Participate(ctx context.Context, duty core.Duty) error {
return nil // Not an eager start timer, wait for Propose to start.
}

// TODO(corver): Remove debug log before v0.17 release.
log.Debug(ctx, "Consensus participated", z.Any("duty", duty))

if _, running := c.getInstanceIO(duty); running {
return nil // Instance already running.
}
Expand All @@ -341,33 +347,34 @@ func (c *Component) Participate(ctx context.Context, duty core.Duty) error {

// runInstance blocks and runs a consensus instance for the given duty.
// It returns an error or nil when the context is cancelled.
// Note each instance may only be run once.
func (c *Component) runInstance(ctx context.Context, duty core.Duty) (err error) {
roundTimer := c.timerFunc(duty)
ctx = log.WithTopic(ctx, "qbft")
ctx = log.WithCtx(ctx, z.Any("duty", duty))
ctx, cancel := context.WithCancel(ctx)
defer cancel()

if !c.deadliner.Add(duty) {
log.Warn(ctx, "Skipping consensus for expired duty", nil)
return nil
}

log.Debug(ctx, "QBFT consensus instance starting",
z.Any("peers", c.peerLabels),
z.Any("timer", string(roundTimer.Type())),
)

peerIdx, err := c.getPeerIdx()
if err != nil {
return err
}

inst, _ := c.getInstanceIO(duty)
defer func() {
inst.errCh <- err // Send resulting error to errCh.
}()

if !c.deadliner.Add(duty) {
log.Warn(ctx, "Skipping consensus for expired duty", nil)
return nil
}

peerIdx, err := c.getPeerIdx()
if err != nil {
return err
}

// Instrument consensus instance.
var decided bool
decideCallback := func(qcommit []qbft.Msg[core.Duty, [32]byte]) {
Expand Down

0 comments on commit 63b59f3

Please sign in to comment.