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

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


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

commit c0ee98928c87828da4135b1b2df4babf00c7eb76
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 52583ce0afe..9325d6b4565 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
@@ -253,6 +253,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 1b7013f3018..9e96932a696 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
@@ -107,11 +107,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