Skip to content

fix: prevent ticker resource leak in chain tracker#2217

Open
nimrod-teich wants to merge 1 commit intomainfrom
fix/ticker-leak-chain-tracker
Open

fix: prevent ticker resource leak in chain tracker#2217
nimrod-teich wants to merge 1 commit intomainfrom
fix/ticker-leak-chain-tracker

Conversation

@nimrod-teich
Copy link
Contributor

Fixed a resource leak where blockGapTicker was not being stopped when the chain tracker goroutine exits. Added defer statement to ensure the ticker is properly stopped when context is cancelled.

Changes:

  • Added defer blockGapTicker.Stop() in chain_tracker.go start() method
  • Added TestChainTrackerTickerCleanup to verify proper cleanup on context cancellation
  • Added TestChainTrackerMultipleInstancesNoLeaks to test multiple instances lifecycle

This ensures that when the chain tracker is stopped (via context cancellation), all resources including the ticker are properly released, preventing memory leaks in long-running applications.

Description

Closes: #XXXX


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • read the contribution guide
  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the main branch
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

@codecov
Copy link

codecov bot commented Feb 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
consensus 8.54% <ø> (ø)
protocol 33.86% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
protocol/chaintracker/chain_tracker.go 61.47% <100.00%> (+2.14%) ⬆️

... and 10 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link

github-actions bot commented Feb 1, 2026

Test Results

    7 files  ±0     85 suites  ±0   29m 31s ⏱️ - 2m 42s
3 347 tests +2  3 346 ✅ +2  1 💤 ±0  0 ❌ ±0 
3 540 runs  +2  3 539 ✅ +2  1 💤 ±0  0 ❌ ±0 

Results for commit cafebf1. ± Comparison against base commit 7fe7354.

♻️ This comment has been updated with latest results.

Fixed a resource leak where blockGapTicker was not being stopped when
the chain tracker goroutine exits. Added defer statement to ensure
the ticker is properly stopped when context is cancelled.

Changes:
- Added defer blockGapTicker.Stop() in chain_tracker.go start() method
- Added TestChainTrackerTickerCleanup to verify proper cleanup on context cancellation
- Added TestChainTrackerMultipleInstancesNoLeaks to test multiple instances lifecycle

This ensures that when the chain tracker is stopped (via context cancellation),
all resources including the ticker are properly released, preventing memory
leaks in long-running applications.
@nimrod-teich nimrod-teich force-pushed the fix/ticker-leak-chain-tracker branch from 96b5176 to cafebf1 Compare February 2, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant