deployments: fix data races (#14121)

* deployments: fix data races

Both priority and state related fields may be mutated concurrently and
need to be accessed with the lock acquired.
This commit is contained in:
Michael Schurter 2022-08-16 10:50:40 -07:00 committed by GitHub
parent db97e08163
commit 285979e96c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View file

@ -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(),

View file

@ -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
}