diff --git a/.changelog/10907.txt b/.changelog/10907.txt new file mode 100644 index 000000000000..a709b2dc445a --- /dev/null +++ b/.changelog/10907.txt @@ -0,0 +1,4 @@ +```release-note:bug +client: Fixed a bug where a restarted client may start an already completed tasks in rare conditions +``` + diff --git a/client/client.go b/client/client.go index 6252e9500451..ee82f4da7e6d 100644 --- a/client/client.go +++ b/client/client.go @@ -1980,8 +1980,15 @@ func (c *Client) watchAllocations(updates chan *allocUpdates) { NodeID: c.NodeID(), SecretID: c.secretNodeID(), QueryOptions: structs.QueryOptions{ - Region: c.Region(), - AllowStale: true, + Region: c.Region(), + + // Make a consistent read query when the client starts + // to avoid acting on stale data that predates this + // client state before a client restart. + // + // After the first request, only require monotonically + // increasing state. + AllowStale: false, }, } var resp structs.NodeClientAllocsResponse @@ -2131,7 +2138,8 @@ OUTER: c.logger.Debug("updated allocations", "index", resp.Index, "total", len(resp.Allocs), "pulled", len(allocsResp.Allocs), "filtered", len(filtered)) - // Update the query index. + // After the first request, only require monotonically increasing state. + req.AllowStale = true if resp.Index > req.MinQueryIndex { req.MinQueryIndex = resp.Index }