apache/pulsar · error · IllegalStateException

Failed to initialize OAuth2 IdP TLS factory: ${cause.getMess

Error message

Failed to initialize OAuth2 IdP TLS factory: ${cause.getMessage}

What it means

The asynchronous OAuth2 IdP TLS-factory initialization completed exceptionally. The factory is closed and this IllegalStateException is thrown with the message suffixed by cause.getMessage() and the original cause attached. It indicates a TLS/keystore configuration problem surfaced during init.

Source

Thrown at pulsar-client/src/main/java/org/apache/pulsar/client/impl/auth/oauth2/StandaloneOAuth2HttpClientFactory.java:117

        }
    }

    private static PulsarTlsFactory buildIdpTlsFactory(TlsPolicy policy, int refreshIntervalSeconds,
            ScheduledExecutorService executor) {
        FileBasedTlsFactory factory = new FileBasedTlsFactory(
                Map.of(TlsPurpose.CLIENT_OAUTH2, policy),
                FileBasedTlsFactorySettings.builder().refreshIntervalSeconds(refreshIntervalSeconds).build(),
                Map.of());
        try {
            factory.initialize(initContext(executor)).get();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            closeQuietly(factory);
            throw new IllegalStateException("Interrupted initializing OAuth2 IdP TLS factory", e);
        } catch (ExecutionException e) {
            closeQuietly(factory);
            Throwable cause = e.getCause() != null ? e.getCause() : e;
            throw new IllegalStateException("Failed to initialize OAuth2 IdP TLS factory: " + cause.getMessage(),
                    cause);
        }
        return factory;
    }

    private static TlsFactoryInitContext initContext(ScheduledExecutorService executor) {
        return new TlsFactoryInitContext() {
            @Override
            public Map<String, String> params() {
                return Map.of();
            }

            @Override
            public ScheduledExecutorService scheduler() {
                return executor;
            }

            @Override

View on GitHub (pinned to 820761864e)

Solutions

  1. Read the wrapped cause (getCause()) — it names the actual TLS failure.
  2. Verify the trust/key store file exists and is readable at the configured absolute path.
  3. Check passwords and KeyStore type in the TLS config match the actual file format.
  4. Confirm certificates are valid/unexpired and the JVM supports the configured TLS version/algorithm.

Example fix

// before
map.put("tlsTrustCertsFilePath", "/etc/certs/ca.pem"); // file missing -> init fails
// after
// ensure the file exists and is a valid PEM bundle first, then:
map.put("tlsTrustCertsFilePath", "/etc/certs/ca-bundle.crt");
Defensive patterns

Strategy: try-catch

Validate before calling

static void validateTlsFiles(Map<String,String> conf) {
    String path = conf.get("tlsTrustCertsFilePath");
    if (path != null && !java.nio.file.Files.isReadable(java.nio.file.Path.of(path))) {
        throw new IllegalStateException("Trust certs file not readable: " + path);
    }
}

Try / catch

try {
    client = AuthenticationFactoryOAuth2.clientCredentials(issuerUrl, credFile, audience);
} catch (IllegalStateException e) {
    if (e.getMessage().startsWith("Failed to initialize OAuth2 IdP TLS factory")) {
        // real reason is in the cause chain
        e.getCause().printStackTrace();
        throw new RuntimeException("Fix TLS config (keystore path/password/certs): " + e.getCause().getMessage(), e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Any failure inside TLS factory initialization: SSLContext/keystore file missing or unreadable, wrong keystore/truststore password, unsupported TLS algorithm or provider, invalid PEM/key material in the oauth2 TLS config parameters.

Common situations: tlsTrustCertsFilePath pointing at a missing or non-PEM file; corrupt or expired certificates; wrong KeyStore type (JKS vs PKCS12); JDK lacking the requested TLS provider; relative paths resolved against the wrong working directory.

Understand the failure class

Related errors


AI-assisted analysis of apache/pulsar@820761864e (2026-09-06). Data as JSON: /api/errors/1ad669b9cc421b09. Report an issue: GitHub.