From 56c00baceaddba22628eea5c5a7dd0843c9e29c4 Mon Sep 17 00:00:00 2001 From: Garet Halliday <me@garet.holiday> Date: Fri, 15 Sep 2023 20:39:39 -0500 Subject: [PATCH] fix backoff --- lib/gat/pool/pool.go | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/lib/gat/pool/pool.go b/lib/gat/pool/pool.go index 210837e1..22ca2e24 100644 --- a/lib/gat/pool/pool.go +++ b/lib/gat/pool/pool.go @@ -3,7 +3,6 @@ package pool import ( "errors" "sync" - "sync/atomic" "time" "github.com/google/uuid" @@ -25,8 +24,6 @@ type Pool struct { closed chan struct{} - isRetrying atomic.Bool - recipes map[string]*recipe.Recipe clients map[uuid.UUID]*Client clientsByKey map[[8]byte]*Client @@ -147,15 +144,15 @@ func (T *Pool) removeRecipe(name string) { } func (T *Pool) scaleUp() { - if T.isRetrying.Load() { - // there is another goroutine trying to retry - return - } - backoff := T.options.ServerReconnectInitialTime - retrying := false for { + select { + case <-T.closed: + return + default: + } + name, r := func() (string, *recipe.Recipe) { T.mu.RLock() defer T.mu.RUnlock() @@ -176,9 +173,6 @@ func (T *Pool) scaleUp() { if r != nil { err := T.scaleUpL1(name, r) if err == nil { - if retrying { - T.isRetrying.Store(false) - } return } @@ -187,20 +181,9 @@ func (T *Pool) scaleUp() { if backoff == 0 { // no backoff - if retrying { - T.isRetrying.Store(false) - } return } - if !retrying { - if T.isRetrying.Swap(true) { - // another goroutine beat us - return - } - retrying = true - } - time.Sleep(backoff) backoff *= 2 -- GitLab