void-ptr974 commented on code in PR #25915:
URL: https://github.com/apache/pulsar/pull/25915#discussion_r3353757697
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractTopic.java:
##########
@@ -810,7 +856,8 @@ public CompletableFuture<Optional<Long>>
addProducer(Producer producer,
log.warn("Attempting to add producer to a
terminated topic");
throw new TopicTerminatedException("Topic was
already terminated");
}
- return internalAddProducer(producer).thenApply(ignore
-> {
+ return internalAddProducer(producer).thenCompose(__ ->
this.startReplProducers())
Review Comment:
This introduces a race in producer registration.
After `internalAddProducer()` succeeds, the producer is already in
`producers`, but `usageCount` is only incremented after `startReplProducers()`
completes. For persistent topics, that call can wait on an async policy lookup.
During this window, `PersistentTopic.delete()` can still see
`currentUsageCount() == 0` and treat the topic as idle, even though a producer
has already been registered.
Please keep the previous ordering and increment `usageCount` immediately
after `internalAddProducer()` succeeds, before starting repl producers.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]