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

penghui pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/branch-4.0 by this push:
     new 40979f52151 [fix] Avoid NPE when closing an uninitialized 
SameAuthParamsLookupAutoClusterFailover (#23911)
40979f52151 is described below

commit 40979f52151cb41c4e32a30cbda649d8ccc0b855
Author: Matteo Merli <[email protected]>
AuthorDate: Wed Jan 29 18:28:39 2025 -0800

    [fix] Avoid NPE when closing an uninitialized 
SameAuthParamsLookupAutoClusterFailover (#23911)
    
    (cherry picked from commit 12b057999f5674ae6da6b04ff8bd212d1904cc88)
---
 .../org/apache/pulsar/client/impl/PulsarClientImpl.java    |  3 +++
 .../impl/SameAuthParamsLookupAutoClusterFailover.java      | 14 ++++++++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git 
a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarClientImpl.java
 
b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarClientImpl.java
index 871666620b7..9d1e45428e9 100644
--- 
a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarClientImpl.java
+++ 
b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarClientImpl.java
@@ -262,6 +262,9 @@ public class PulsarClientImpl implements PulsarClient {
                     this::reduceConsumerReceiverQueueSize);
             state.set(State.Open);
         } catch (Throwable t) {
+            // Log the exception first, or it could be missed if there are any 
subsequent exceptions in the
+            // shutdown sequence
+            log.error("Failed to create Pulsar client instance.", t);
             shutdown();
             shutdownEventLoopGroup(eventLoopGroupReference);
             closeCnxPool(connectionPoolReference);
diff --git 
a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/SameAuthParamsLookupAutoClusterFailover.java
 
b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/SameAuthParamsLookupAutoClusterFailover.java
index 4beff4719c8..d71ac095a3b 100644
--- 
a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/SameAuthParamsLookupAutoClusterFailover.java
+++ 
b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/SameAuthParamsLookupAutoClusterFailover.java
@@ -105,11 +105,21 @@ public class SameAuthParamsLookupAutoClusterFailover 
implements ServiceUrlProvid
 
     @Override
     public void close() throws Exception {
+        if (closed) {
+            return;
+        }
+
         log.info("Closing service url provider. Current pulsar service: [{}] 
{}", currentPulsarServiceIndex,
                 pulsarServiceUrlArray[currentPulsarServiceIndex]);
+        if (scheduledCheckTask != null) {
+            scheduledCheckTask.cancel(false);
+        }
+
+        if (executor != null) {
+            executor.shutdownNow();
+        }
+
         closed = true;
-        scheduledCheckTask.cancel(false);
-        executor.shutdownNow();
     }
 
     private int firstHealthyPulsarService() {

Reply via email to