apache/pulsar · error · PulsarClientException
Interrupted while creating segment producer
Error message
Interrupted while creating segment producer
What it means
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.
Source
Thrown at pulsar-client-v5/src/main/java/org/apache/pulsar/client/impl/v5/ScalableTopicProducer.java:635
if (segConf.isEncryptionEnabled()) {
segConf.setBatchingEnabled(false);
} else if (segConf.isBatchingEnabled()) {
segConf.setBatcherBuilder(new EntryBucketBatcherBuilder(segment.entryBucketSplits()));
}
}
/**
* Sync wrapper around {@link #getOrCreateSegmentProducerAsync}. Only safe to
* call from user threads (never from a netty IO thread) since it blocks until
* the segment producer is ready.
*/
private org.apache.pulsar.client.api.Producer<T> getOrCreateSegmentProducer(long segmentId)
throws PulsarClientException {
try {
return getOrCreateSegmentProducerAsync(segmentId).get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new PulsarClientException("Interrupted while creating segment producer", e);
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof org.apache.pulsar.client.api.PulsarClientException v4Exc) {
throw new PulsarClientException(v4Exc.getMessage(), v4Exc);
}
if (cause instanceof PulsarClientException v5Exc) {
throw v5Exc;
}
throw new PulsarClientException(cause != null ? cause : e);
}
}
}
View on GitHub (pinned to 820761864e)
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.
Example fix
// before
executor.shutdownNow(); // interrupts in-flight getOrCreateSegmentProducer
// after
executor.shutdown();
if (!executor.awaitTermination(30, TimeUnit.SECONDS)) { executor.shutdownNow(); } Defensive patterns
Strategy: try-catch
Try / catch
try {
producer.send(msg);
} catch (PulsarClientException e) {
if (e.getCause() instanceof InterruptedException) {
Thread.currentThread().interrupt();
} else { throw e; }
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Executor shutdownNow() during send; time-limited tasks interrupting in-flight sends; onLayoutChange invoked on a thread later cancelled; test timeouts interrupting producer threads.
Related errors
- Close interrupted
- ServiceUrlProvider has already been initialized
- Authentication already closed.
- Interrupted initializing OAuth2 IdP TLS factory
- (wraps underlying failure cause)
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/9d9fa03bc82aceae.
Report an issue: GitHub.