Skip to content

Commit

Permalink
Merge pull request #2203 from k-wall/refresh-brokers-leaks-broker
Browse files Browse the repository at this point in the history
fix: prevent RefreshBrokers leaking old brokers
  • Loading branch information
dnwe authored Apr 13, 2022
2 parents 1776783 + 132afa5 commit a7dab62
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 a7dab62

Please sign in to comment.