From 0a8f2f2105b954f933eecf337e5d611ae4301cc0 Mon Sep 17 00:00:00 2001 From: freddygv Date: Fri, 5 Feb 2021 18:00:59 -0700 Subject: [PATCH] Retry send after timer fires, in case no updates occur --- agent/proxycfg/state.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/agent/proxycfg/state.go b/agent/proxycfg/state.go index fcb0302eb..ad1ef61ec 100644 --- a/agent/proxycfg/state.go +++ b/agent/proxycfg/state.go @@ -628,18 +628,27 @@ func (s *state) run() { case s.snapCh <- *snapCopy: s.logger.Trace("Delivered new snapshot to proxy config watchers") - // avoid blocking if a snapshot is already buffered + // Allow the next change to trigger a send + coalesceTimer = nil + + // Skip rest of loop - there is nothing to send since nothing changed on + // this iteration + continue + + // avoid blocking if a snapshot is already buffered, but queue up a retry with a timer default: s.logger.Trace("Failed to deliver new snapshot to proxy config watchers") + + if coalesceTimer == nil { + coalesceTimer = time.AfterFunc(coalesceTimeout, func() { + sendCh <- struct{}{} + }) + } + + // Do not reset coalesceTimer since we just queued a timer-based refresh + continue } - // Allow the next change to trigger a send - coalesceTimer = nil - - // Skip rest of loop - there is nothing to send since nothing changed on - // this iteration - continue - case replyCh := <-s.reqCh: s.logger.Trace("A proxy config snapshot was requested")