From 56b83089447b1c1ec39346a48bc8b9f87cd6452d Mon Sep 17 00:00:00 2001 From: Travis Bischel Date: Mon, 12 Apr 2021 07:31:15 -0600 Subject: [PATCH] client: fix loadCoordinators Once we receive an error, we want to keep the first error and cancel the context so all other requests quit. The conditional was backwards, so we never canceled the other requests and we never saved the first error, which also meant we never returned an error. --- pkg/kgo/client.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/kgo/client.go b/pkg/kgo/client.go index 23d546d9..0b020a75 100644 --- a/pkg/kgo/client.go +++ b/pkg/kgo/client.go @@ -819,7 +819,7 @@ func (cl *Client) loadCoordinators(reload bool, typ int8, names ...string) (map[ var mu sync.Mutex m := make(map[string]*broker) - var errQuit error + var firstErr error var wg sync.WaitGroup for _, name := range names { @@ -836,8 +836,8 @@ func (cl *Client) loadCoordinators(reload bool, typ int8, names ...string) (map[ defer mu.Unlock() if err != nil { - if errQuit != nil { - errQuit = err + if firstErr == nil { + firstErr = err cancel() } return @@ -847,7 +847,7 @@ func (cl *Client) loadCoordinators(reload bool, typ int8, names ...string) (map[ } wg.Wait() - return m, errQuit + return m, firstErr } func (cl *Client) handleAdminReq(ctx context.Context, req kmsg.Request) ResponseShard {