Reset WaitIndex when a smaller WaitIndex is returned #26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
According to the Consul doc1, resolvers must handle the case that Consul returns a WaitIndex that was lower then the requested one, by doing another query with a WaitIndex of 0.
If this is not done, updates can be missed.
Quote from the Documentation1
Reset the index if it goes backwards. While indexes in general are
monotonically increasing(i.e. they should only ever increase as time passes),
there are several real-world scenarios in which they can go backwards for a
given query. Implementations must check to see if a returned index is lower
than the previous value, and if it is, should reset index to 0 - effectively
restarting their blocking loop. Failure to do so may cause the client to miss
future updates for an unbounded time, or to use an invalid index value that
causes no blocking and increases load on the servers. Cases where this can
occur include: If a raft snapshot is restored on the servers with older
version of the data. KV list operations where an item with the highest index
is removed. A Consul upgrade changes the way watches work to optimize them
with more granular indexes.
follow-up issue to add a unit-test: #27
Footnotes
https://developer.hashicorp.com/consul/api-docs/features/blocking ↩ ↩2