diff --git a/broker/src/main/java/org/apache/rocketmq/broker/client/ProducerManager.java b/broker/src/main/java/org/apache/rocketmq/broker/client/ProducerManager.java index 61ceae53860d16d87045b1af067650f8529424fb..f3eed652ceaede7cb406ff2d17ce386b1ac594bb 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/client/ProducerManager.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/client/ProducerManager.java @@ -53,7 +53,15 @@ public class ProducerManager { try { if (this.groupChannelLock.tryLock(LOCK_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) { try { - newGroupChannelTable.putAll(groupChannelTable); + Iterator>> iter = groupChannelTable.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry> entry = iter.next(); + String key = entry.getKey(); + HashMap val = entry.getValue(); + HashMap tmp = new HashMap(); + tmp.putAll(val); + newGroupChannelTable.put(key, tmp); + } } finally { groupChannelLock.unlock(); } diff --git a/broker/src/test/java/org/apache/rocketmq/broker/client/ProducerManagerTest.java b/broker/src/test/java/org/apache/rocketmq/broker/client/ProducerManagerTest.java index 08dbb9c754c51c198285e749adcbc2eeb25df0c0..33995ff2fe3fe0f5a38c06ae7147991906c20bed 100644 --- a/broker/src/test/java/org/apache/rocketmq/broker/client/ProducerManagerTest.java +++ b/broker/src/test/java/org/apache/rocketmq/broker/client/ProducerManagerTest.java @@ -87,4 +87,12 @@ public class ProducerManagerTest { assertThat(channelMap).isNull(); } + @Test + public void testGetGroupChannelTable() throws Exception { + producerManager.registerProducer(group, clientInfo); + HashMap oldMap = producerManager.getGroupChannelTable().get(group); + + producerManager.unregisterProducer(group, clientInfo); + assertThat(oldMap.size()).isNotEqualTo(0); + } } \ No newline at end of file