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

lhotari 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 3552cd9c093 [fix][client] Fix ArrayIndexOutOfBoundsException when 
using SameAuthParamsLookupAutoClusterFailover (#23336)
3552cd9c093 is described below

commit 3552cd9c093b1cdde2e4c3910db855bea9f069df
Author: fengyubiao <[email protected]>
AuthorDate: Fri Aug 29 10:00:21 2025 +0800

    [fix][client] Fix ArrayIndexOutOfBoundsException when using 
SameAuthParamsLookupAutoClusterFailover (#23336)
    
    (cherry picked from commit 8fd5bf5fd6e81c4344e5fea1adce667fc877553f)
---
 .../SameAuthParamsLookupAutoClusterFailover.java   | 49 ++++++++++++----------
 1 file changed, 28 insertions(+), 21 deletions(-)

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 6286bc0322c..743f2e15164 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
@@ -71,29 +71,36 @@ public class SameAuthParamsLookupAutoClusterFailover 
implements ServiceUrlProvid
         this.executor = EventLoopUtil.newEventLoopGroup(1, false,
                 new 
ExecutorProvider.ExtendedThreadFactory("broker-service-url-check"));
         scheduledCheckTask = executor.scheduleAtFixedRate(() -> {
-            if (closed) {
-                return;
-            }
-            checkPulsarServices();
-            int firstHealthyPulsarService = firstHealthyPulsarService();
-            if (firstHealthyPulsarService == currentPulsarServiceIndex) {
-                return;
-            }
-            if (firstHealthyPulsarService < 0) {
-                int failoverTo = findFailoverTo();
-                if (failoverTo < 0) {
-                    // No healthy pulsar service to connect.
-                    log.error("Failed to choose a pulsar service to connect, 
no one pulsar service is healthy. Current"
-                            + " pulsar service: [{}] {}. States: {}, Counters: 
{}", currentPulsarServiceIndex,
-                            pulsarServiceUrlArray[currentPulsarServiceIndex], 
Arrays.toString(pulsarServiceStateArray),
-                            Arrays.toString(checkCounterArray));
+            try {
+                if (closed) {
+                    return;
+                }
+                checkPulsarServices();
+                int firstHealthyPulsarService = firstHealthyPulsarService();
+                if (firstHealthyPulsarService == currentPulsarServiceIndex) {
+                    return;
+                }
+                if (firstHealthyPulsarService < 0) {
+                    int failoverTo = findFailoverTo();
+                    if (failoverTo < 0) {
+                        // No healthy pulsar service to connect.
+                        log.error(
+                                "Failed to choose a pulsar service to connect, 
no one pulsar service is healthy."
+                                        + " Current pulsar service: [{}] {}. 
States: {}, Counters: {}",
+                                currentPulsarServiceIndex,
+                                
pulsarServiceUrlArray[currentPulsarServiceIndex],
+                                Arrays.toString(pulsarServiceStateArray),
+                                Arrays.toString(checkCounterArray));
+                    } else {
+                        // Failover to low priority pulsar service.
+                        updateServiceUrl(failoverTo);
+                    }
                 } else {
-                    // Failover to low priority pulsar service.
-                    updateServiceUrl(failoverTo);
+                    // Back to high priority pulsar service.
+                    updateServiceUrl(firstHealthyPulsarService);
                 }
-            } else {
-                // Back to high priority pulsar service.
-                updateServiceUrl(firstHealthyPulsarService);
+            } catch (Exception ex) {
+                log.error("Failed to re-check cluster status", ex);
             }
         }, checkHealthyIntervalMs, checkHealthyIntervalMs, 
TimeUnit.MILLISECONDS);
     }

Reply via email to