{"record":{"id":"c2db638dcc1f1d9b","repo":"apache/pulsar","slug":"subscription-already-exists-for-topic","errorCode":null,"errorMessage":"Subscription already exists for topic","messagePattern":"Subscription already exists for topic","errorType":"http","errorClass":"RestException","httpStatus":409,"severity":"error","filePath":"pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java","lineNumber":2496,"sourceCode":"            AsyncResponse asyncResponse, String subscriptionName,\n            MessageIdImpl targetMessageId, boolean authoritative, boolean replicated,\n            Map<String, String> properties) {\n\n        validateTopicOwnershipAsync(topicName, authoritative)\n                .thenCompose(__ -> validateTopicOperationAsync(topicName, TopicOperation.SUBSCRIBE, subscriptionName))\n                .thenCompose(__ -> pulsar().getBrokerService().isAllowAutoTopicCreationAsync(topicName))\n                .thenCompose(isAllowAutoTopicCreation -> pulsar().getBrokerService()\n                        .getTopic(topicName.toString(), isAllowAutoTopicCreation))\n                .thenApply(optTopic -> {\n                    if (optTopic.isPresent()) {\n                        return optTopic.get();\n                    } else {\n                        throw new RestException(Status.PRECONDITION_FAILED,\n                                \"Topic does not exist and cannot be auto-created\");\n                    }\n        }).thenCompose(topic -> {\n            if (topic.getSubscriptions().containsKey(subscriptionName)) {\n                throw new RestException(Status.CONFLICT, \"Subscription already exists for topic\");\n            }\n\n            return topic.createSubscription(subscriptionName, InitialPosition.Latest, replicated, properties);\n        }).thenCompose(subscription -> {\n            // Mark the cursor as \"inactive\" as it was created without a real consumer connected\n            ((PersistentSubscription) subscription).deactivateCursor();\n            return subscription.resetCursor(\n                    PositionFactory.create(targetMessageId.getLedgerId(), targetMessageId.getEntryId()));\n        }).thenRun(() -> {\n            log.info()\n                    .attr(\"topic\", topicName)\n                    .attr(\"subscription\", subscriptionName)\n                    .attr(\"messageId\", targetMessageId)\n                    .log(\"Successfully created subscription at message id\");\n            asyncResponse.resume(Response.noContent().build());\n        }).exceptionally(ex -> {\n            Throwable t = (ex instanceof CompletionException ? ex.getCause() : ex);\n            if (!(t instanceof WebApplicationException)) {","sourceCodeStart":2478,"sourceCodeEnd":2514,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java#L2478-L2514","documentation":"While creating a subscription, the broker found the subscription name already exists on the topic (durable subscription already registered), so the create request is rejected with 409 Conflict instead of replacing the existing subscription.","triggerScenarios":"Thrown at pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java:2496 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use the existing subscription rather than creating it again","Delete the subscription first if it must be recreated (durable subscription data is lost)"],"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"}