From 0d550ff4b82c1641de6c9ffe90e7d7f85c9dd1cf 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 0fd4a747e..1ecb23e85 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 10cca4f9ca20e645ebaa6b6d068031daee114b1f 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 1ecb23e85..6813b5973 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 bb419342300edefb30ca87ecf5a3c49732728717 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 6813b5973..8e4fd5e11 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