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.
prevent calling ReportError with the same error in a row
The resolver already prevents that UpdateState is called for the same
address multiples times in a row, do the same when reporting errors.
Only call ReportError() if the same error hasn't been reported in the
last call and UpdateState hasn't been called last.
This prevents that we unnecessary report the same state multiple times
and trigger the same events for the connection.
The code is refactored to store the last reported state in the
consulResolver struct and reporting addresses and errors is moved to
separate methods.
retry resolving on errors
Some grpc-go load balancing policies, including round_robin, do not take
care about retrying resolving after an error is reported1.
This causes that when querying consul fails the grpc connection can hang
in a state without addresses until the connection idle timeout expires,
despite consul became reachable.
To prevent it, retry periodically querying consul when it fails.
This is done by creating a timer that calls ResolveNow() after it
expires.
The backoff implementation from commit f1f1a15 is recovered and modified
to randomize subtracting or adding the jitter from the delay, use
smaller pauses and returning the default implementation from a
constructor instead of defining it as package variable.
Closes: #41
Footnotes
https://github.com/grpc/grpc-go/issues/7729 ↩