You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by lh...@apache.org on 2025/09/04 21:39:46 UTC

(pulsar) branch branch-3.0 updated: [fix][client] Fix ArrayIndexOutOfBoundsException when using SameAuthParamsLookupAutoClusterFailover (#23336)

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

commit 8214bfded94bdcff695c3b67eb2373345745c712
Author: fengyubiao <yu...@streamnative.io>
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 5e244f70ee0..75db7366264 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
@@ -73,29 +73,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);
     }