{"record":{"id":"9d9fa03bc82aceae","repo":"apache/pulsar","slug":"interrupted-while-creating-segment-producer","errorCode":null,"errorMessage":"Interrupted while creating segment producer","messagePattern":"Interrupted while creating segment producer","errorType":"exception","errorClass":"PulsarClientException","httpStatus":null,"severity":"error","filePath":"pulsar-client-v5/src/main/java/org/apache/pulsar/client/impl/v5/ScalableTopicProducer.java","lineNumber":635,"sourceCode":"        if (segConf.isEncryptionEnabled()) {\n            segConf.setBatchingEnabled(false);\n        } else if (segConf.isBatchingEnabled()) {\n            segConf.setBatcherBuilder(new EntryBucketBatcherBuilder(segment.entryBucketSplits()));\n        }\n    }\n\n    /**\n     * Sync wrapper around {@link #getOrCreateSegmentProducerAsync}. Only safe to\n     * call from user threads (never from a netty IO thread) since it blocks until\n     * the segment producer is ready.\n     */\n    private org.apache.pulsar.client.api.Producer<T> getOrCreateSegmentProducer(long segmentId)\n            throws PulsarClientException {\n        try {\n            return getOrCreateSegmentProducerAsync(segmentId).get();\n        } catch (InterruptedException e) {\n            Thread.currentThread().interrupt();\n            throw new PulsarClientException(\"Interrupted while creating segment producer\", e);\n        } catch (ExecutionException e) {\n            Throwable cause = e.getCause();\n            if (cause instanceof org.apache.pulsar.client.api.PulsarClientException v4Exc) {\n                throw new PulsarClientException(v4Exc.getMessage(), v4Exc);\n            }\n            if (cause instanceof PulsarClientException v5Exc) {\n                throw v5Exc;\n            }\n            throw new PulsarClientException(cause != null ? cause : e);\n        }\n    }\n}\n","sourceCodeStart":617,"sourceCodeEnd":648,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client-v5/src/main/java/org/apache/pulsar/client/impl/v5/ScalableTopicProducer.java#L617-L648","documentation":"getOrCreateSegmentProducer() blocks on getOrCreateSegmentProducerAsync().get(); if that wait is interrupted, the interrupt flag is restored and a PulsarClientException with this message is thrown. It means a per-segment producer was not created because the caller's thread was interrupted, not because of a broker error.","triggerScenarios":"Any send, layout-change callback, or eager attach that needs to lazily create a v4 producer for a segment while the invoking thread is interrupted during the future wait.","commonSituations":"Executor shutdownNow() during send; time-limited tasks interrupting in-flight sends; onLayoutChange invoked on a thread later cancelled; test timeouts interrupting producer threads.","solutions":["Avoid interrupting threads performing producer creation; use producer lifecycle (closeAsync) for shutdown.","Retry the send/attach after the interruption; the segment producer creation is idempotent.","If interruption stems from executor policy, switch to graceful shutdown or dedicated producer threads.","Check for systemic slow producer creation (broker latency) that makes waits long enough to be interrupted."],"exampleFix":"// before\nexecutor.shutdownNow(); // interrupts in-flight getOrCreateSegmentProducer\n// after\nexecutor.shutdown();\nif (!executor.awaitTermination(30, TimeUnit.SECONDS)) { executor.shutdownNow(); }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    producer.send(msg);\n} catch (PulsarClientException e) {\n    if (e.getCause() instanceof InterruptedException) {\n        Thread.currentThread().interrupt();\n    } else { throw e; }\n}","preventionTips":["Avoid shutdownNow() while sends may be creating segment producers","Pre-warm segment producers (eager attach) to reduce interruptible waits","Use graceful executor shutdown with awaitTermination"],"tags":["interruption","segment-producer","lifecycle","pulsar-client"],"backgroundTag":"thread-interrupted","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}