RockteMQ-AI commented on issue #10906: URL: https://github.com/apache/rocketmq/issues/10906#issuecomment-5250069597
**Issue Evaluation** Category: `type/bug` | Status: **Confirmed** This is a well-documented resource leak in `MQClientManager.getOrCreateMQClientInstance`. The analysis is accurate — concurrent calls for the same client ID construct multiple `MQClientInstance` candidates, and the losing candidates leak their `ScheduledThreadPoolExecutor` (with 30 periodic stats tasks) because the tasks are registered during construction before `putIfAbsent` determines the winner. **Root Cause:** The `getOrCreate` pattern is not atomic — construction happens outside the map guard, so all concurrent callers build full instances (including scheduler threads) even though only one survives in `factoryTable`. **Impact:** Leaked non-daemon scheduler threads + 30 periodic tasks per lost race. In long-running applications with repeated client creation (e.g., test suites, dynamic client provisioning), this accumulates thread pool overhead indefinitely. **Severity:** Medium — does not cause data loss or incorrect behavior, but degrades runtime resources over time. **Suggested Fix Direction:** Move the `putIfAbsent` before construction (compute-if-absent pattern), or defer `ConsumerStatsManager` / scheduler creation until after the instance wins the map insertion. An automated fix proposal can be generated. Reply `/approve` to proceed with PR generation. --- *Automated evaluation by github-manager* -- 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]
