poorbarcode opened a new pull request, #21540: URL: https://github.com/apache/pulsar/pull/21540
### Motivation In the current implementation, the Broker just removes `topicFuture` from the mapping `BrokerService.topics` and never closes it<sup>[1]<sup>. The orphan topics will be depended on by `SystemTopicBasedTopicPoliciesService.listeners`, which is for notice of topic policy changes. This issue would cause OOM<sup>[2]</sup>. **[1]**: https://github.com/apache/pulsar/blob/master/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java#L1725-L1748 ```java ... persistentTopic.stopReplProducers().whenCompleteAsync((v, exception) -> { topics.remove(topic, topicFuture); }, executor()); }).exceptionally((ex) -> { ... persistentTopic.stopReplProducers().whenCompleteAsync((v, exception) -> { topics.remove(topic, topicFuture); topicFuture.completeExceptionally(ex); }, executor()); ... }); ``` **[2]**: Thousands of orphan PersistentTopics <img width="1468" alt="Screenshot 2023-11-08 at 00 54 24" src="https://github.com/apache/pulsar/assets/25195800/7f422e9e-7b4a-4f2e-8a55-623c1fd7c272"> ### Modifications - close the PersistentTopic if creating failed due to timeout. - close the PersistentTopic if initialize failed. ### Documentation <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. --> - [ ] `doc` <!-- Your PR contains doc changes. --> - [ ] `doc-required` <!-- Your PR changes impact docs and you will update later --> - [x] `doc-not-needed` <!-- Your PR changes do not impact docs --> - [ ] `doc-complete` <!-- Docs have been already added --> ### Matching PR in forked repository PR in forked repository: x -- 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]
