This is an automated email from the ASF dual-hosted git repository.
tison pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-client-go.git
The following commit(s) were added to refs/heads/master by this push:
new 2a15a251 [Fix] Multiple calls to client.Close causes panic (#1046)
2a15a251 is described below
commit 2a15a251d25bd2a6276051d71873e9e106cc1e85
Author: crossoverJie <[email protected]>
AuthorDate: Sun Sep 10 11:43:30 2023 +0800
[Fix] Multiple calls to client.Close causes panic (#1046)
---
pulsar/client_impl.go | 10 +++++++---
pulsar/client_impl_test.go | 7 +++++++
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/pulsar/client_impl.go b/pulsar/client_impl.go
index c283f5a8..801eab3f 100644
--- a/pulsar/client_impl.go
+++ b/pulsar/client_impl.go
@@ -20,6 +20,7 @@ package pulsar
import (
"fmt"
"net/url"
+ "sync"
"time"
"github.com/apache/pulsar-client-go/pulsar/auth"
@@ -47,6 +48,7 @@ type client struct {
metrics *internal.Metrics
tcClient *transactionCoordinatorClient
memLimit internal.MemoryLimitController
+ closeOnce sync.Once
log log.Logger
}
@@ -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()
+ })
}
diff --git a/pulsar/client_impl_test.go b/pulsar/client_impl_test.go
index bb28371f..78dc1cae 100644
--- a/pulsar/client_impl_test.go
+++ b/pulsar/client_impl_test.go
@@ -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()
+}