Fix panic due to return nil pulsar client (#27429)

Signed-off-by: bigsheeper <yihao.dai@zilliz.com>
This commit is contained in:
yihao.dai 2023-09-28 16:19:26 +08:00 committed by GitHub
parent 01c4499a12
commit f962fc186f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,8 +48,10 @@ var once sync.Once
// NewClient creates a pulsarClient object
// according to the parameter opts of type pulsar.ClientOptions
func NewClient(tenant string, namespace string, opts pulsar.ClientOptions) (*pulsarClient, error) {
var err error
once.Do(func() {
c, err := pulsar.NewClient(opts)
var c pulsar.Client
c, err = pulsar.NewClient(opts)
if err != nil {
log.Error("Failed to set pulsar client: ", zap.Error(err))
return
@ -61,7 +63,7 @@ func NewClient(tenant string, namespace string, opts pulsar.ClientOptions) (*pul
}
sc = cli
})
return sc, nil
return sc, err
}
// CreateProducer create a pulsar producer from options