apache/pulsar · error · TopicTerminatedException

Topic was already terminated

Error message

Topic was already terminated

What it means

Producer-attachment guard in AbstractTopic.addProducer: after ownership/epoch checks, the topic is found to be in the terminated state (a terminate() already wrote the last message id), so no new producers are accepted on it.

Source

Thrown at pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractTopic.java:939

    @Override
    public CompletableFuture<Optional<Long>> addProducer(Producer producer,
                                                         CompletableFuture<Void> producerQueuedFuture) {
        checkArgument(producer.getTopic() == this);

        return brokerService.checkTopicNsOwnership(getName())
                .thenCompose(__ ->
                        incrementTopicEpochIfNeeded(producer, producerQueuedFuture))
                .thenCompose(producerEpoch -> {
                    lock.writeLock().lock();
                    try {
                        checkTopicFenced();
                        if (isMigrated()) {
                            log.warn("Attempting to add producer to a migrated topic");
                            throw new TopicMigratedException("Topic was already migrated");
                        } else if (isTerminated()) {
                            log.warn("Attempting to add producer to a terminated topic");
                            throw new TopicTerminatedException("Topic was already terminated");
                        }
                        return internalAddProducer(producer).thenApply(ignore -> {
                            USAGE_COUNT_UPDATER.incrementAndGet(this);
                            log.debug()
                                    .attr("producerName", producer.getProducerName())
                                    .attr("usageCount", USAGE_COUNT_UPDATER.get(this))
                                    .log("Added producer");
                            return producerEpoch;
                        });
                    } catch (BrokerServiceException e) {
                        return FutureUtil.failedFuture(e);
                    } finally {
                        lock.writeLock().unlock();
                    }
                });
    }

    protected CompletableFuture<Optional<Long>> incrementTopicEpochIfNeeded(Producer producer,

View on GitHub (pinned to 820761864e)

Solutions

  1. Create a new topic if further publishing is needed
  2. Remove the terminate policy/markers if the topic must be reused
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractTopic.java:939 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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