diff --git a/helper/stats/cpu.go b/helper/stats/cpu.go index 34afe8113b0..b3596a428da 100644 --- a/helper/stats/cpu.go +++ b/helper/stats/cpu.go @@ -1,14 +1,23 @@ package stats import ( + "context" "fmt" "math" "sync" + "time" multierror "github.com/hashicorp/go-multierror" "github.com/shirou/gopsutil/cpu" ) +const ( + // cpuInfoTimeout is the timeout used when gathering CPU info. This is used + // to override the default timeout in gopsutil which has a tendency to + // timeout on Windows. + cpuInfoTimeout = 10 * time.Second +) + var ( cpuMhzPerCore float64 cpuModelName string @@ -28,7 +37,8 @@ func Init() error { } var cpuInfo []cpu.InfoStat - if cpuInfo, err = cpu.Info(); err != nil { + ctx, _ := context.WithTimeout(context.Background(), cpuInfoTimeout) + if cpuInfo, err = cpu.InfoWithContext(ctx); err != nil { merrs = multierror.Append(merrs, fmt.Errorf("Unable to obtain CPU information: %v", err)) }