{"record":{"id":"6b61d17cf6822839","repo":"apache/pulsar","slug":"topic-was-already-terminated","errorCode":null,"errorMessage":"Topic was already terminated","messagePattern":"Topic was already terminated","errorType":"exception","errorClass":"TopicTerminatedException","httpStatus":null,"severity":"error","filePath":"pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractTopic.java","lineNumber":939,"sourceCode":"\n    @Override\n    public CompletableFuture<Optional<Long>> addProducer(Producer producer,\n                                                         CompletableFuture<Void> producerQueuedFuture) {\n        checkArgument(producer.getTopic() == this);\n\n        return brokerService.checkTopicNsOwnership(getName())\n                .thenCompose(__ ->\n                        incrementTopicEpochIfNeeded(producer, producerQueuedFuture))\n                .thenCompose(producerEpoch -> {\n                    lock.writeLock().lock();\n                    try {\n                        checkTopicFenced();\n                        if (isMigrated()) {\n                            log.warn(\"Attempting to add producer to a migrated topic\");\n                            throw new TopicMigratedException(\"Topic was already migrated\");\n                        } else if (isTerminated()) {\n                            log.warn(\"Attempting to add producer to a terminated topic\");\n                            throw new TopicTerminatedException(\"Topic was already terminated\");\n                        }\n                        return internalAddProducer(producer).thenApply(ignore -> {\n                            USAGE_COUNT_UPDATER.incrementAndGet(this);\n                            log.debug()\n                                    .attr(\"producerName\", producer.getProducerName())\n                                    .attr(\"usageCount\", USAGE_COUNT_UPDATER.get(this))\n                                    .log(\"Added producer\");\n                            return producerEpoch;\n                        });\n                    } catch (BrokerServiceException e) {\n                        return FutureUtil.failedFuture(e);\n                    } finally {\n                        lock.writeLock().unlock();\n                    }\n                });\n    }\n\n    protected CompletableFuture<Optional<Long>> incrementTopicEpochIfNeeded(Producer producer,","sourceCodeStart":921,"sourceCodeEnd":957,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractTopic.java#L921-L957","documentation":"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.","triggerScenarios":"Thrown at pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractTopic.java:939 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Create a new topic if further publishing is needed","Remove the terminate policy/markers if the topic must be reused"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}