Skip to content

Commit

Permalink
Merge pull request #5906 from hashicorp/b-alloc-stale-updates
Browse files Browse the repository at this point in the history
client: defensive against getting stale alloc updates
  • Loading branch information
Mahmood Ali authored Jul 2, 2019
2 parents 7fd3658 + 2e1978e commit 22960f8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1767,6 +1767,9 @@ func (c *Client) allocSync() {
// allocUpdates holds the results of receiving updated allocations from the
// servers.
type allocUpdates struct {
// index is index of server store snapshot used for fetching alloc status
index uint64

// pulled is the set of allocations that were downloaded from the servers.
pulled map[string]*structs.Allocation

Expand Down Expand Up @@ -1944,6 +1947,7 @@ OUTER:
filtered: filtered,
pulled: pulledAllocs,
migrateTokens: resp.MigrateTokens,
index: resp.Index,
}

select {
Expand Down
2 changes: 1 addition & 1 deletion client/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func diffAllocs(existing map[string]uint64, allocs *allocUpdates) *diffResult {
_, filtered := allocs.filtered[existID]

// If not updated or filtered, removed
if !pulled && !filtered {
if !pulled && !filtered && allocs.index > existIndex {
result.removed = append(result.removed, existID)
continue
}
Expand Down

0 comments on commit 22960f8

Please sign in to comment.