From 4a13cafa98bff078c0c52bbf860eff9c284fb819 Mon Sep 17 00:00:00 2001 From: Harmen Date: Thu, 29 Dec 2016 21:58:46 +0100 Subject: [PATCH 1/3] reset watch's lastIndex on error When a -dev agent is restarted it'll have a clean state, including a reset index. A watch() will reconnect after a restart, but it won't notice that the index counter has reset and it will keep waiting until we reached the old index again, which is wrong. Resetting the index will prevent that and makes watch work for -dev agents. --- watch/plan.go | 1 + 1 file changed, 1 insertion(+) diff --git a/watch/plan.go b/watch/plan.go index 0fd4a747e7..1ecb23e856 100644 --- a/watch/plan.go +++ b/watch/plan.go @@ -57,6 +57,7 @@ OUTER: if err != nil { // Perform an exponential backoff failures++ + p.lastIndex = 1 retry := retryInterval * time.Duration(failures*failures) if retry > maxBackoffTime { retry = maxBackoffTime From 021cc2017d967a3aee11bded32a4e3f5cfa9e04a Mon Sep 17 00:00:00 2001 From: Harmen Date: Tue, 17 Jan 2017 09:02:39 +0100 Subject: [PATCH 2/3] reset index to 0, not to 1 --- watch/plan.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/watch/plan.go b/watch/plan.go index 1ecb23e856..6813b59735 100644 --- a/watch/plan.go +++ b/watch/plan.go @@ -57,7 +57,7 @@ OUTER: if err != nil { // Perform an exponential backoff failures++ - p.lastIndex = 1 + p.lastIndex = 0 retry := retryInterval * time.Duration(failures*failures) if retry > maxBackoffTime { retry = maxBackoffTime From d7b5f4144735479273977b83843e73bf96cc4466 Mon Sep 17 00:00:00 2001 From: Harmen Date: Tue, 17 Jan 2017 09:02:53 +0100 Subject: [PATCH 3/3] reset the watch index when somehow the index goes backwards --- watch/plan.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/watch/plan.go b/watch/plan.go index 6813b59735..8e4fd5e11a 100644 --- a/watch/plan.go +++ b/watch/plan.go @@ -86,6 +86,9 @@ OUTER: if oldIndex != 0 && reflect.DeepEqual(p.lastResult, result) { continue } + if p.lastIndex < oldIndex { + p.lastIndex = 0 + } // Handle the updated result p.lastResult = result