AnonHxy commented on code in PR #19934: URL: https://github.com/apache/pulsar/pull/19934#discussion_r1156653236
########## pulsar-broker/src/test/java/org/apache/pulsar/broker/service/nonpersistent/NonPersistentStickyKeyDispatcherMultipleConsumersTest.java: ########## @@ -94,6 +94,15 @@ public void setup() throws Exception { new HashRangeAutoSplitStickyKeyConsumerSelector()); } + @Test(timeOut = 10000) + public void testAddConsumerWhenClosed() throws Exception { + nonpersistentDispatcher.close().get(); + Consumer consumer = mock(Consumer.class); + nonpersistentDispatcher.addConsumer(consumer); + verify(consumer, times(1)).disconnect(); + assertEquals(0, nonpersistentDispatcher.getConsumers().size()); Review Comment: I find that it's not easy to access the `selector`, and verify `assertEquals(0, nonpersistentDispatcher.getConsumers().size());` is enough. So maybe we needn't change it @poorbarcode ########## pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentStickyKeyDispatcherMultipleConsumers.java: ########## @@ -102,6 +102,11 @@ public class PersistentStickyKeyDispatcherMultipleConsumers extends PersistentDi @Override public synchronized void addConsumer(Consumer consumer) throws BrokerServiceException { + if (IS_CLOSED_UPDATER.get(this) == TRUE) { + log.warn("[{}] Dispatcher is already closed. Closing consumer {}", name, consumer); + consumer.disconnect(); + return; + } super.addConsumer(consumer); Review Comment: Is there any other comments :) @poorbarcode -- 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-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org