guyinyou opened a new pull request, #1305: URL: https://github.com/apache/rocketmq-clients/pull/1305
## Problem When Go clients are repeatedly created and destroyed, resources leak: 1. **Goroutine leak**: `GracefulStop()` only called `UnRegisterClient()` but never `shutdown()` on the per-client `ClientManager`, leaving 4 background goroutines (heartbeat, idle check, stats, sync settings) and RPC connections alive forever. This was a regression from #235 which made `ClientManager` per-client but forgot to add the shutdown call. 2. **Telemetry session leak**: `endpointsTelemetryClientTable` sessions were never released on client close, leaking gRPC streaming connections. 3. **Metrics cardinality explosion**: All clients shared global OpenCensus Views with `client_id` as a tag key. Each new client added new tag combinations that were never cleaned up, causing unbounded growth in metrics data. ## Fix 1. **ClientManager shutdown**: Call `shutdown()` instead of `UnRegisterClient()` in `GracefulStop()` to stop background goroutines and close RPC connections. 2. **Telemetry session cleanup**: Release all sessions in `GracefulStop()` before shutting down the client manager. Added nil check in `release()` for cases where the observer was never initialized. 3. **Per-client metrics isolation**: Use `view.NewMeter()` (available since OpenCensus v0.22.4) to give each client its own Meter, Measures, Views, and Exporter. On client close, the Meter is stopped and views are unregistered. The `client_id` tag is preserved in exported metric data — the exported metric names and labels are unchanged. ## Test Results 1000 iterations × 50 concurrent workers, each creating/sending/destroying a producer: | Metric | Master | Fix | |--------|--------|-----| | Goroutine leak | +13,814 | +385 | | Memory Sys | +342 MB | +17 MB | | Memory Alloc | +200 MB | +3.5 MB | Goroutines on fix branch stabilize after ~500 iterations (no linear growth), while master grows linearly at ~1,300 per 100 iterations. -- 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]
