Skip to content

Commit

Permalink
fix: prevent RefreshBrokers leaking old brokers
Browse files Browse the repository at this point in the history
  • Loading branch information
k-wall committed Apr 13, 2022
1 parent 3144ec8 commit 132afa5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 132afa5

Please sign in to comment.