apache/pulsar · warning · RestException
Subscription has active connected consumers
Error message
Subscription has active connected consumers
What it means
HTTP 412 PRECONDITION_FAILED returned when deleting a subscription whose cursor still has active connected consumers. The per-partition delete throws PreconditionFailedException (broker refuses to remove a subscription in use) and the aggregated handler converts it to 'Subscription has active connected consumers'.
Source
Thrown at pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java:1721
try {
adminClient = pulsar().getAdminClient();
} catch (PulsarServerException e) {
return CompletableFuture.failedFuture(e);
}
for (int i = 0; i < partitionMetadata.partitions; i++) {
TopicName topicNamePartition = topicName.getPartition(i);
futures.add(adminClient.topics()
.deleteSubscriptionAsync(topicNamePartition.toString(), subName, force));
}
return FutureUtil.waitForAll(futures).handle((result, exception) -> {
if (exception != null) {
Throwable t = exception.getCause();
if (t instanceof NotFoundException) {
throw new RestException(Status.NOT_FOUND,
"Subscription not found");
} else if (t instanceof PreconditionFailedException) {
throw new RestException(Status.PRECONDITION_FAILED,
"Subscription has active connected consumers");
} else {
throw new RestException(t);
}
}
return null;
});
}
return internalDeleteSubscriptionForNonPartitionedTopicAsync(subName, authoritative, force);
});
}
});
}
// Note: this method expects the caller to check authorization
private CompletableFuture<Void> internalDeleteSubscriptionForNonPartitionedTopicAsync(String subName,
boolean authoritative,
boolean force) {View on GitHub (pinned to 820761864e)
Solutions
- Disconnect all consumers of the subscription, then retry the delete.
- Use force delete (`DELETE .../subscription/{sub}?force=true` or `pulsar-admin topics unsubscribe --force`) after confirming the consumers should be evicted.
- Identify connected consumers with `pulsar-admin topics stats <topic>` (look at the subscription's consumers list) and shut them down first.
- Schedule subscription cleanup during maintenance windows when consumers are stopped.
Example fix
// before curl -X DELETE .../persistent/t/ns/topic/subscription/old-sub // 412 // after curl -X DELETE .../persistent/t/ns/topic/subscription/old-sub?force=true
Defensive patterns
Strategy: retry
Validate before calling
TopicStats stats = admin.topics().getStats(topic);
boolean hasConsumers = stats.getSubscriptions().getOrDefault(subName,
new SubscriptionStats()).consumers.stream().findAny().isPresent();
if (!hasConsumers) {
admin.topics().deleteSubscription(topic, subName);
} Try / catch
try {
admin.topics().deleteSubscription(topic, subName);
} catch (PulsarAdminException.PreconditionFailedException e) {
// consumers still connected: disconnect then retry, or use force=true
} Prevention
- Verify consumer counts in topic stats before deleting subscriptions
- Stop consumers during maintenance windows for cleanup
- Use force delete only after confirming eviction is safe
When it happens
Trigger: DELETE .../subscription/{subName} (or force=false unsubscribe) while consumers are connected on that subscription; also via `pulsar-admin topics unsubscribe` with connected readers/consumers using shared/exclusive subscriptions.
Common situations: Ops tries to clean up a subscription during business hours with live consumers; shared-subscription consumers reconnecting between check and delete; consumers stuck due to network issues but still registered; batch jobs deleting stale subscriptions without checking consumer count first.
Related errors
- Subscription not found
- getSubNotFoundErrorMessage(topicName.toString(), subName)
- cluster data is required
- Cannot delete non empty namespace
- Namespace does not exist
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/4a1950137eee3b39.
Report an issue: GitHub.