Skip to content

Commit

Permalink
make a single timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay Camp committed Sep 12, 2019
1 parent 0605521 commit 8fd2dc4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions metadata/hostmetadata/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ func GetCPU() (info *CPU, err error) {
var cpus []cpu.InfoStat

// On Windows this can sometimes take longer than the default timeout (3 seconds).
ctx, _ := context.WithTimeout(context.Background(), cpuTimeout)
ctx, cancel := context.WithTimeout(context.Background(), cpuTimeout)
defer cancel()

if cpus, err = cpuInfo(ctx); err != nil {
return info, err
}

info.HostPhysicalCPUs = len(cpus)

ctx, _ = context.WithTimeout(context.Background(), cpuTimeout)

// get logical cpu stats
if info.HostLogicalCPUs, err = cpuCounts(ctx, true); err != nil {
return info, err
Expand Down

0 comments on commit 8fd2dc4

Please sign in to comment.