zjncs opened a new pull request, #11114:
URL: https://github.com/apache/rocketmq/pull/11114
## Motivation
`ConsumerManager` has three paths that remove a consumer group from
`consumerTable` once its last channel is gone: `unregisterConsumer`,
`doChannelCloseEvent`, and `scanNotActiveChannel`. The first two clean up the
group's `topicGroupTable` entries and fire the `UNREGISTER` listener event:
```java
ConsumerGroupInfo remove = this.consumerTable.remove(group);
if (remove != null) {
...
callConsumerIdsChangeListener(ConsumerGroupEvent.UNREGISTER, group);
clearTopicGroupTable(remove);
}
```
`scanNotActiveChannel` only does `it.remove()`:
```java
if (channelInfoTable.isEmpty()) {
LOGGER.warn("SCAN: remove expired channel ... consumerGroup={}", group);
it.remove();
}
```
When a consumer client dies without closing the channel (process kill,
network partition), the scan path is the one that eventually removes the group.
Its omission means:
- `queryTopicConsumeByWho(topic)` keeps returning the dead group forever —
`QUERY_TOPIC_CONSUME_BY_WHO` (used by admin tools/mqadmin/console) reports
groups as consumers of a topic long after they went offline, and nothing ever
cleans the entry since only re-registration writes to `topicGroupTable`.
- The `UNREGISTER` event is never fired, so
`DefaultConsumerIdsChangeListener` never calls
`consumerFilterManager.unRegister(group)` and the group's consumer filter
registrations leak.
## Modification
In `scanNotActiveChannel`, after removing the empty group, fire the
`UNREGISTER` listener event and call `clearTopicGroupTable(consumerGroupInfo)`,
exactly matching the other two removal paths.
## Test Evidence
**Fail-before** (unpatched code, new test
`ConsumerManagerTest#scanNotActiveChannelClearsTopicGroupTableTest` — register
a consumer on a topic, expire its channel, scan, then ask who consumes the
topic):
```
docker exec rmq-build mvn -q -pl broker test
-Dtest='ConsumerManagerTest#scanNotActiveChannelClearsTopicGroupTableTest'
-Dsurefire.failIfNoSpecifiedTests=true
Tests run: 1, Failures: 1 ... java.lang.AssertionError
// queryTopicConsumeByWho(TOPIC) still returns the removed group
```
**Pass-after** (full class with the fix):
```
docker exec rmq-build mvn -q -pl broker test -Dtest='ConsumerManagerTest'
-Dsurefire.failIfNoSpecifiedTests=true
Tests run: 14, Failures: 0, Errors: 0, Skipped: 0
```
No associated issue (self-discovered during a broker-module self-audit).
--
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]