{"record":{"id":"573bf71190c3cab0","repo":"apache/pulsar","slug":"serviceurlprovider-has-already-been-initialized","errorCode":null,"errorMessage":"ServiceUrlProvider has already been initialized","messagePattern":"ServiceUrlProvider has already been initialized","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"pulsar-client/src/main/java/org/apache/pulsar/client/impl/AutoClusterFailover.java","lineNumber":99,"sourceCode":"        this.secondaryAuthentications = builder.secondaryAuthentications;\n        this.secondaryTlsTrustCertsFilePaths = builder.secondaryTlsTrustCertsFilePaths;\n        this.secondaryTlsTrustStorePaths = builder.secondaryTlsTrustStorePaths;\n        this.secondaryTlsTrustStorePasswords = builder.secondaryTlsTrustStorePasswords;\n        this.failoverDelayNs = builder.failoverDelayNs;\n        this.switchBackDelayNs = builder.switchBackDelayNs;\n        this.currentPulsarServiceUrl = builder.primary;\n        this.recoverTimestamp = -1;\n        this.failedTimestamp = -1;\n        this.intervalMs = builder.checkIntervalMs;\n        this.resolver = new PulsarServiceNameResolver();\n        this.executor = Executors.newSingleThreadScheduledExecutor(\n                new ExecutorProvider.ExtendedThreadFactory(\"pulsar-service-provider\"));\n    }\n\n    @Override\n    public synchronized void initialize(PulsarClient client) {\n        if (this.pulsarClient != null) {\n            throw new IllegalStateException(\"ServiceUrlProvider has already been initialized\");\n        }\n        this.pulsarClient = (PulsarClientImpl) client;\n        this.addressResolver = pulsarClient.getAddressResolver();\n        ClientConfigurationData config = pulsarClient.getConfiguration();\n        if (config != null) {\n            this.primaryAuthentication = config.getAuthentication();\n            this.primaryTlsTrustCertsFilePath = config.getTlsTrustCertsFilePath();\n            this.primaryTlsTrustStorePath = config.getTlsTrustStorePath();\n            this.primaryTlsTrustStorePassword = config.getTlsTrustStorePassword();\n        }\n\n        // start to probe primary cluster active or not\n        this.executor.scheduleAtFixedRate(catchingAndLoggingThrowables(() -> {\n            if (currentPulsarServiceUrl.equals(primary)) {\n                // current service url is primary, probe whether it is down\n                probeAndUpdateServiceUrl(secondary, secondaryAuthentications, secondaryTlsTrustCertsFilePaths,\n                        secondaryTlsTrustStorePaths, secondaryTlsTrustStorePasswords);\n            } else {","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client/src/main/java/org/apache/pulsar/client/impl/AutoClusterFailover.java#L81-L117","documentation":"Single-initialization guard in AutoClusterFailover.initialize: the ServiceUrlProvider has already been initialized (typically the PulsarClient called initialize twice, or a new client reused the provider), so the second call is rejected to avoid re-registering the state updater and resetting failover state.","triggerScenarios":"Thrown at pulsar-client/src/main/java/org/apache/pulsar/client/impl/AutoClusterFailover.java:99 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Initialize the failover client only once per builder","Create a new instance instead of re-initializing"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}