This is an automated email from the ASF dual-hosted git repository.

baodi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-client-node.git


The following commit(s) were added to refs/heads/master by this push:
     new 6c01e36  [fix][client] prevent garbage collection of token-supplier 
(#412)
6c01e36 is described below

commit 6c01e3675035dc0f04be35b67eebc37918934838
Author: Charlie Ede <[email protected]>
AuthorDate: Wed Jun 11 03:35:23 2025 +0200

    [fix][client] prevent garbage collection of token-supplier (#412)
    
    * Add persistent reference to Auth Object
    
    * Update src/Client.cc
    
    ---------
    
    Co-authored-by: Yunze Xu <[email protected]>
---
 src/Client.cc | 3 ++-
 src/Client.h  | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/Client.cc b/src/Client.cc
index b204fa9..80052f0 100644
--- a/src/Client.cc
+++ b/src/Client.cc
@@ -144,7 +144,8 @@ Client::Client(const Napi::CallbackInfo &info) : 
Napi::ObjectWrap<Client>(info)
   if (clientConfig.Has(CFG_AUTH) && clientConfig.Get(CFG_AUTH).IsObject()) {
     Napi::Object obj = clientConfig.Get(CFG_AUTH).ToObject();
     if (obj.Has(CFG_AUTH_PROP) && obj.Get(CFG_AUTH_PROP).IsObject()) {
-      Authentication *auth = 
Authentication::Unwrap(obj.Get(CFG_AUTH_PROP).ToObject());
+      this->authRef_ = 
Napi::Persistent(obj.Get(CFG_AUTH_PROP).As<Napi::Object>());
+      Authentication *auth = Authentication::Unwrap(this->authRef_.Value());
       pulsar_client_configuration_set_auth(cClientConfig.get(), 
auth->GetCAuthentication());
     }
   }
diff --git a/src/Client.h b/src/Client.h
index ee81bb5..b761d36 100644
--- a/src/Client.h
+++ b/src/Client.h
@@ -54,6 +54,7 @@ class Client : public Napi::ObjectWrap<Client> {
   std::shared_ptr<pulsar_client_t> cClient;
   std::shared_ptr<pulsar_client_configuration_t> cClientConfig;
   pulsar_logger_level_t logLevel = pulsar_logger_level_t::pulsar_INFO;
+  Napi::ObjectReference authRef_;
 
   Napi::Value CreateProducer(const Napi::CallbackInfo &info);
   Napi::Value Subscribe(const Napi::CallbackInfo &info);

Reply via email to