cancel
func returned by context.WithCancel VET-V0011 84 span.AddAttributes(trace.Int64Attribute("slot", int64(slot))) // lint:ignore uintcast -- This conversion is OK for tracing.
85
86 deadline := v.SlotDeadline(slot)
87 slotCtx, cancel := context.WithDeadline(ctx, deadline) 88 log := log.WithField("slot", slot)
89 log.WithField("deadline", deadline).Debug("Set deadline for proposals and attestations")
90
76 span.End()
77 sub.Unsubscribe()
78 close(accountsChangedChan)
79 return // Exit if context is canceled. 80 case slot := <-v.NextSlot():
81 if !healthTracker.IsHealthy() {
82 continue
The cancellation function returned by context.WithCancel
, WithTimeout
, and
WithDeadline
must be called or the new context will remain live until its
parent context is cancelled. (The background context is never cancelled.)
This is usually an issue either because the variable was assigned to the blank identifier, or because there exists a control-flow path from the call to a return statement and that path does not "use" the cancel function.
For example, cancel
is not used on all paths below, hence, is an issue.
func f(cond bool) {
var _, cancel = context.WithCancel(bg)
if cond {
x = cancel
}
}