Skip to content

Commit

Permalink
[Fix] Multiple calls to client.Close causes panic (#1046)
Browse files Browse the repository at this point in the history
  • Loading branch information
crossoverJie authored Sep 10, 2023
1 parent 28a6b49 commit 2a15a25
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pulsar/client_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package pulsar
import (
"fmt"
"net/url"
"sync"
"time"

"github.com/apache/pulsar-client-go/pulsar/auth"
Expand Down Expand Up @@ -47,6 +48,7 @@ type client struct {
metrics *internal.Metrics
tcClient *transactionCoordinatorClient
memLimit internal.MemoryLimitController
closeOnce sync.Once

log log.Logger
}
Expand Down Expand Up @@ -266,7 +268,9 @@ func (c *client) TopicPartitions(topic string) ([]string, error) {
}

func (c *client) Close() {
c.handlers.Close()
c.cnxPool.Close()
c.lookupService.Close()
c.closeOnce.Do(func() {
c.handlers.Close()
c.cnxPool.Close()
c.lookupService.Close()
})
}
7 changes: 7 additions & 0 deletions pulsar/client_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1238,3 +1238,10 @@ func TestAutoCloseIdleConnection(t *testing.T) {

cli.Close()
}

func TestMultipleCloseClient(t *testing.T) {
client, err := NewClient(ClientOptions{URL: serviceURL})
assert.Nil(t, err)
client.Close()
client.Close()
}

0 comments on commit 2a15a25

Please sign in to comment.