diff --git a/nomad/deploymentwatcher/deployment_watcher.go b/nomad/deploymentwatcher/deployment_watcher.go index dec0c8f2c..32648c081 100644 --- a/nomad/deploymentwatcher/deployment_watcher.go +++ b/nomad/deploymentwatcher/deployment_watcher.go @@ -840,10 +840,12 @@ func (w *deploymentWatcher) getEval() *structs.Evaluation { // on the previous version that are then "watched" on a leader that's on // the new version. This would result in an eval with its priority set to // zero which would be bad. This therefore protects against that. + w.l.Lock() priority := w.d.EvalPriority if priority == 0 { priority = w.j.Priority } + w.l.Unlock() return &structs.Evaluation{ ID: uuid.Generate(), diff --git a/nomad/deploymentwatcher/deployments_watcher.go b/nomad/deploymentwatcher/deployments_watcher.go index 56617430f..46db7a73c 100644 --- a/nomad/deploymentwatcher/deployments_watcher.go +++ b/nomad/deploymentwatcher/deployments_watcher.go @@ -193,7 +193,12 @@ func (w *Watcher) watchDeployments(ctx context.Context) { // getDeploys retrieves all deployments blocking at the given index. func (w *Watcher) getDeploys(ctx context.Context, minIndex uint64) ([]*structs.Deployment, uint64, error) { - resp, index, err := w.state.BlockingQuery(w.getDeploysImpl, minIndex, ctx) + // state can be updated concurrently + w.l.Lock() + stateStore := w.state + w.l.Unlock() + + resp, index, err := stateStore.BlockingQuery(w.getDeploysImpl, minIndex, ctx) if err != nil { return nil, 0, err }