the aggrCancel function is not used on all paths (possible context leak)
1000 }
1001 aggrCancel()
1002 errChan = nil
1003 aggrCtx, aggrCancel = context.WithCancel(ctx)1004 case <-ctx.Done():
1005 return
1006 }
this return statement may be reached without using the aggrCancel var defined on line 1003
1002 errChan = nil
1003 aggrCtx, aggrCancel = context.WithCancel(ctx)
1004 case <-ctx.Done():
1005 return1006 }
1007 }
1008}
Description
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
}
}