fix unrelated data race that randomly cropped up in CI

This commit is contained in:
Matthew Jaffee 2021-12-07 18:30:51 -06:00
parent 3d3080df8b
commit b0d29bb425

5
api.go
View file

@ -996,7 +996,10 @@ func (api *API) Usage(ctx context.Context, remote bool) (map[string]NodeUsage, e
return resp, nil
}
if api.usageCache.lastCalcDuration < usageCacheMinDuration {
api.usageCache.muAssign.Lock()
lastCalc := api.usageCache.lastCalcDuration
api.usageCache.muAssign.Unlock()
if lastCalc < usageCacheMinDuration {
err := api.ResetUsageCache()
if err != nil {
api.server.logger.Infof("could not reset usageCache: %s", err)