Added deferred cancel to prevent context leaks

This commit is contained in:
Charlie Voiselle 2018-05-10 18:52:54 -04:00
parent 823ccf79ba
commit fd952eefbc
1 changed files with 2 additions and 1 deletions

View File

@ -37,7 +37,8 @@ func Init() error {
}
var cpuInfo []cpu.InfoStat
ctx, _ := context.WithTimeout(context.Background(), cpuInfoTimeout)
ctx, cancel := context.WithTimeout(context.Background(), cpuInfoTimeout)
defer cancel()
if cpuInfo, err = cpu.InfoWithContext(ctx); err != nil {
merrs = multierror.Append(merrs, fmt.Errorf("Unable to obtain CPU information: %v", err))
}