fix(gossip): stop membership tracker ticker on channel shutdown by remo-lab · Pull Request #5364 · hyperledger/fabric
Bug Description:
A time.Ticker is created when initializing the membership tracker, but only the ticker’s channel is retained.
During shutdown, other resources are cleaned up, however the ticker itself is never stopped, violating Go’s ticker lifecycle requirements.
Need for Change:
-The gossip channel creates a time.Ticker for membership tracking but does not stop it when the channel is shut down.
This leads to a resource leak where ticker goroutines continue running after the channel lifecycle has ended.
-In long-running peers or environments where gossip channels are frequently started and stopped, this can accumulate and cause unnecessary memory and CPU usage.
Summary of Fix:
-This PR ensures proper cleanup of the membership tracker ticker by:
-Storing a reference to the created time.Ticker in the membership tracker
-Explicitly stopping the ticker during gossip channel shutdown
-Adding a nil check to safely handle cleanup
The fix is minimal and does not alter any existing behavior beyond proper resource management.
Impact:
-Prevents goroutine and memory leaks
-Improves stability of long-running peers
-Ensures correct lifecycle management of background timers
-Particularly important when multiple gossip channels are created over time
Verification:
-Existing gossip channel tests pass
-No linter or build errors
-Ticker is now correctly stopped during shutdown
-The issue was reproduced using a small standalone program that repeatedly starts and stops gossip channels and compares -goroutine counts before and after shutdown. A terminal screenshot demonstrating this behavior is attached.

A dedicated unit test was not added to avoid flaky goroutine-count assertions in CI environments.