You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/11/08 08:00:43 UTC

[GitHub] [pulsar] codelipenghui commented on a change in pull request #12654: Remove unused listeners if it have no listeners.

codelipenghui commented on a change in pull request #12654:
URL: https://github.com/apache/pulsar/pull/12654#discussion_r744478204



##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/SystemTopicBasedTopicPoliciesService.java
##########
@@ -474,7 +475,13 @@ public void registerListener(TopicName topicName, TopicPolicyListener<TopicPolic
 
     @Override
     public void unregisterListener(TopicName topicName, TopicPolicyListener<TopicPolicies> listener) {
-        listeners.computeIfAbsent(topicName, k -> Lists.newCopyOnWriteArrayList()).remove(listener);

Review comment:
       It should be a problem if thread A reaches line 478 first, then thread B reaches line 473 and then add a listener. After that, thread A continues to remove the listener, finally, the added listener will be removed, but actually, the `unregisterListener` operation happens first, we will get unexpected behavior.




-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org