Skip to content

Conversation

@remo-lab
Copy link
Contributor

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.
Screenshot 2025-12-18 104221
A dedicated unit test was not added to avoid flaky goroutine-count assertions in CI environments.

@remo-lab remo-lab requested a review from a team as a code owner December 18, 2025 06:39
Signed-off-by: remo-lab <remo@DESKTOP-V3SPST8.localdomain>
@remo-lab remo-lab force-pushed the fix/gossip-channel-stop-membership-ticker branch from 7b5221e to 4cd1628 Compare December 18, 2025 06:41
@remo-lab
Copy link
Contributor Author

remo-lab commented Dec 21, 2025

Hi @denyeart @C0rWin @yacovm ,This PR addresses a small resource cleanup issue in the gossip channel by ensuring the membership tracker ticker is properly stopped during shutdown.
Whenever you have some time, I’d really appreciate a review. Thanks!

@yacovm yacovm merged commit 59cf596 into hyperledger:main Dec 21, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants