{"record":{"id":"3e27d5420d2406ba","repo":"apache/pulsar","slug":"interrupted-while-probing-the-client-tls-factory","errorCode":null,"errorMessage":"Interrupted while probing the client TLS factory","messagePattern":"Interrupted while probing the client TLS factory","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"pulsar-client/src/main/java/org/apache/pulsar/client/impl/tls/ClientTlsFactorySupport.java","lineNumber":626,"sourceCode":"     * {@link TlsContextAcquisition}, so a custom factory that supplies only the JDK {@code SSLContext}\n     * fallback probes successfully via the framework-synthesized Netty context.\n     *\n     * @param factory   the initialized factory\n     * @param purpose   the purpose to probe\n     * @param synthesis the settings baked into a synthesized Netty context on the fallback path\n     */\n    public static void probe(PulsarTlsFactory factory, TlsPurpose purpose, TlsSynthesisSpec synthesis) {\n        try {\n            Optional<TlsHandle<SslContext>> handle =\n                    TlsContextAcquisition.acquireNettyContext(factory, purpose, synthesis).get();\n            if (handle.isEmpty()) {\n                throw new IllegalStateException(\"Client TLS factory \" + factory.getClass().getName()\n                        + \" supplied no Netty SslContext for purpose \" + purpose);\n            }\n            handle.get().dispose();\n        } catch (InterruptedException e) {\n            Thread.currentThread().interrupt();\n            throw new IllegalStateException(\"Interrupted while probing the client TLS factory\", e);\n        } catch (ExecutionException | CompletionException e) {\n            Throwable cause = e.getCause() != null ? e.getCause() : e;\n            throw new IllegalArgumentException(\"Client TLS configuration is invalid for purpose \" + purpose\n                    + \": \" + cause.getMessage(), cause);\n        }\n    }\n\n    private static void initializeBlocking(PulsarTlsFactory factory, TlsFactoryInitContext context)\n            throws Exception {\n        try {\n            factory.initialize(context).get();\n        } catch (ExecutionException e) {\n            Throwable cause = e.getCause() != null ? e.getCause() : e;\n            if (cause instanceof Exception ex) {\n                throw ex;\n            }\n            throw new RuntimeException(cause);\n        }","sourceCodeStart":608,"sourceCodeEnd":644,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client/src/main/java/org/apache/pulsar/client/impl/tls/ClientTlsFactorySupport.java#L608-L644","documentation":"During probe(), waiting for the asynchronous TlsContextAcquisition.acquireNettyContext future was interrupted. The method restores the interrupt flag and rethrows as IllegalStateException. This means the calling thread was interrupted while the TLS factory was being validated.","triggerScenarios":"Thread calling resolveClientTlsFactory (e.g. during PulsarClient creation) is interrupted via Thread.interrupt() while blocked on the acquisition future.","commonSituations":"Application shutdown/executors interrupting client-construction threads; timeout watchdogs cancelling slow TLS init; mismanaged thread pools interrupting tasks.","solutions":["Find what interrupted the thread (shutdown hook, executor shutdownNow, timeout) and delay client creation until after those run.","Retry PulsarClient creation on a non-interrupted thread.","Avoid interrupting threads that are building clients; use separate lifecycle coordination.","If intentional shutdown, catch the IllegalStateException and treat client setup as aborted."],"exampleFix":"// before\nexecutor.shutdownNow();\nPulsarClient client = PulsarClient.builder().build(); // may be interrupted\n// after\nPulsarClient client = PulsarClient.builder().build();\nexecutor.shutdownNow();","handlingStrategy":"try-catch","validationCode":"if (Thread.currentThread().isInterrupted()) {\n    // clear/decide before doing TLS setup\n    Thread.interrupted();\n}","typeGuard":null,"tryCatchPattern":"try {\n    ClientTlsFactorySupport.probe(factory, purpose, spec);\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"Interrupted while probing\")) {\n        Thread.currentThread().interrupt(); // preserve status, abort setup\n    }\n}","preventionTips":["Don't interrupt threads while clients are being constructed","Sequence executor shutdown after client lifecycle teardown","Avoid shutdownNow() on pools doing client init","Treat InterruptedException as cancellation, not noise"],"tags":["tls","interrupt","threading","probe"],"backgroundTag":"thread-interrupted","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"}