Skip to content

Store Gateway: stop the concurrent data bytes tracker - #7977

Open
blaketsk wants to merge 2 commits into
cortexproject:masterfrom
blaketsk:storegateway-stop-bytes-tracker
Open

blaketsk wants to merge 2 commits into
cortexproject:masterfrom
blaketsk:storegateway-stop-bytes-tracker

Conversation

@blaketsk

Copy link
Copy Markdown

What this PR does:

Stops the store-gateway concurrent data bytes tracker, whose goroutine publishing cortex_storegateway_concurrent_data_bytes_peak was never stopped:

  • ThanosBucketStores.Stop() returned nil without stopping the tracker. It now stops it.
  • newThanosBucketStores() leaked the tracker when it failed after creating it (users scanner, matchers cache, index cache or chunks pool setup). The tracker is now stopped on these error paths.
  • StoreGateway.starting() left the bucket stores running when it failed, because BasicService does not call the stopping function after a failed start. The bucket stores are now stopped together with the subservices in the existing error handler.
  • Tests now stop the trackers and bucket stores they create.

Running the pkg/storegateway tests with goleak.VerifyTestMain reported 1696 leaked goroutines before this change (1688 of them publishPeakLoop) and 28 after. The remaining ones are unrelated (parquet shard cache, Thanos index header reader pool and third-party init goroutines) and are left for follow-ups.

TestBucketStores_StopShouldStopConcurrentDataBytesTracker and the new assertion in TestStoreGateway_InitialSyncFailure fail without the fix.

Which issue(s) this PR fixes:
Part of #3962

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]
  • docs/configuration/v1-guarantees.md updated if this PR introduces experimental flags

AI disclosure: per GENAI_POLICY.md, the leak survey, the fix and the tests were prepared with Claude Code. I reviewed and verified the changes.

🤖 Generated with Claude Code

ThanosBucketStores.Stop() did not stop the concurrent data bytes
tracker, so the goroutine publishing the peak bytes metric was never
stopped. The tracker also leaked when newThanosBucketStores() failed
after creating it, and the store-gateway left the bucket stores running
when starting failed, because the stopping function is not called after
a failed start.

Stop the tracker in ThanosBucketStores.Stop() and when the bucket stores
can't be created, stop the bucket stores when starting fails, and stop
trackers and bucket stores in tests. This removes about 1700 goroutines
leaked by the store-gateway tests.

Ref cortexproject#3962

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YDgKpXdZmLs9YSYU1ZSf8d
Signed-off-by: Andrey Osipov <blaketsk@gmail.com>
@blaketsk
blaketsk requested a review from a team as a code owner November 28, 2026 07:48
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YDgKpXdZmLs9YSYU1ZSf8d
Signed-off-by: Andrey Osipov <blaketsk@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant