Skip to content

Commit 94cc109

Browse files
Fabian Hollerfho
authored andcommitted
fix: resolver delayed next query on fast empty responses unnecessarily
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.
1 parent dfa6743 commit 94cc109

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

consul/resolver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ func sortAddresses(addrs []resolver.Address) {
150150

151151
func (c *consulResolver) watcher() {
152152
var lastReportedAddrs []resolver.Address
153-
var lastWaitIndex uint64
154153

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

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

163+
lastWaitIndex := opts.WaitIndex
164+
164165
queryStartTime := time.Now()
165166
addrs, opts.WaitIndex, err = c.query(opts)
166-
lastWaitIndex = opts.WaitIndex
167167
if err != nil {
168168
if errors.Is(err, context.Canceled) {
169169
return

0 commit comments

Comments
 (0)