Skip to content

Commit

Permalink
fix: resolver delayed next query on fast empty responses unnecessarily
Browse files Browse the repository at this point in the history
When consul returned no addresses 2x times in a row but different waitIndices
the next query was delayed for 50ms.
The following query should only be delayed if the same addresses and same
WaitIndex is returned then in the previous call.

The cause was that lastWaitIndex was set to the new waitIndex after the query
was returned, before the check.
  • Loading branch information
fho committed Mar 27, 2020
1 parent dfa6743 commit 94cc109
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions consul/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ func sortAddresses(addrs []resolver.Address) {

func (c *consulResolver) watcher() {
var lastReportedAddrs []resolver.Address
var lastWaitIndex uint64

opts := (&consul.QueryOptions{}).WithContext(c.ctx)

Expand All @@ -161,9 +160,10 @@ func (c *consulResolver) watcher() {
var addrs []resolver.Address
var err error

lastWaitIndex := opts.WaitIndex

queryStartTime := time.Now()
addrs, opts.WaitIndex, err = c.query(opts)
lastWaitIndex = opts.WaitIndex
if err != nil {
if errors.Is(err, context.Canceled) {
return
Expand Down

0 comments on commit 94cc109

Please sign in to comment.