fix(sink): stop progressBlockRate janitor in Stats.Close()#785
Merged
maoueh merged 1 commit intoMay 21, 2026
Merged
Conversation
Fixes streamingfast#786 Stats.Close() stopped dataMsgRate and undoMsgRate but omitted progressBlockRate.Stop(). Each AvgRate* object spawns an internal janitor goroutine on construction; without Stop() that goroutine leaks. In code paths that repeatedly construct and tear down a Sinker (e.g., a continuous-mode loop that builds a fresh Sinker each collection interval), this produces one leaked goroutine per iteration — a linear growth visible in runtime metrics over hours/days. Adds TestStatsCloseStopsAllRateJanitors: creates and closes 50 Stats objects in a loop and asserts NumGoroutine() does not drift upward. Co-Authored-By: Hugo Sjoberg <hugo.sjoberg@amberdata.io> Signed-off-by: Hugo Sjoberg <hugo.sjoberg@amberdata.io>
3685690 to
2aa2114
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #786
Problem
`Stats.Close()` stops `dataMsgRate` and `undoMsgRate` but omits `progressBlockRate.Stop()`.
Each `dmetrics.AvgRate*` object spawns an internal janitor goroutine on construction. Without `Stop()`, that goroutine leaks for the process lifetime.
In code paths that repeatedly construct and tear down a `Sinker` — for example a continuous-mode loop that builds a fresh `Sinker` each collection interval — this produces one leaked goroutine per iteration, creating a linear goroutine growth visible in runtime metrics over hours/days.
Fix
Add the missing `s.progressBlockRate.Stop()` call, symmetric with the other two.
Test
`sink/stats_test.go` — `TestStatsCloseStopsAllRateJanitors`: creates and closes 50 `Stats` objects in a loop and asserts `runtime.NumGoroutine()` does not drift upward (delta ≤ 2). Pre-fix: delta = 50. Post-fix: delta ≈ 0.
Context
Discovered while investigating a goroutine leak in a service using `streamingfast/substreams/sink` in continuous mode. The same bug existed in the now-deprecated `streamingfast/substreams-sink` package and was carried over when the `sink` package was ported into this repo.