From 132afa552e706dd7669670e47d4a916d76ec0e27 Mon Sep 17 00:00:00 2001 From: kwall Date: Fri, 1 Apr 2022 18:42:43 +0100 Subject: [PATCH] fix: prevent RefreshBrokers leaking old brokers --- client.go | 8 ++++++++ client_test.go | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index 8f07e426f..da3779b46 100644 --- a/client.go +++ b/client.go @@ -459,6 +459,14 @@ func (client *client) RefreshBrokers(addrs []string) error { delete(client.brokers, broker.ID()) } + for _, broker := range client.seedBrokers { + _ = broker.Close() + } + + for _, broker := range client.deadSeeds { + _ = broker.Close() + } + client.seedBrokers = nil client.deadSeeds = nil diff --git a/client_test.go b/client_test.go index 60020e5af..4fe4873d2 100644 --- a/client_test.go +++ b/client_test.go @@ -528,11 +528,11 @@ func TestClientRefreshBrokers(t *testing.T) { initialSeed.Returns(metadataResponse1) c, err := NewClient([]string{initialSeed.Addr()}, NewTestConfig()) - client := c.(*client) - if err != nil { t.Fatal(err) } + defer c.Close() + client := c.(*client) if len(client.Brokers()) != 2 { t.Error("Meta broker is not 2")