Reproduction for sentry-ruby yabeda-memory-growth#47
Merged
Conversation
Discovers that Scope#apply_to_telemetry mutates the caller's attributes hash in-place, corrupting yabeda's metric values hash keys and causing every metric increment to create a new orphaned entry. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
sentry-ruby:Scope#apply_to_telemetrymutates the caller's attributes hash in-place, which corrupts hash keys in yabeda'smetric.values(Concurrent::Hash)active_record_instantiation_totalshows 2005 entries for 50 unique kinds (should be 50). RSS growth is 14x worse (+21 MB vs +1.5 MB)Root cause
MetricEvent#initializestores the caller'sattributeshash by reference (@attributes = attributes || {}). ThenScope#apply_to_telemetryadds sentry-specific keys (sentry.sdk.name,sentry.sdk.version,sentry.environment,server.address) directly onto this hash. Sincesentry-yabedapasses the same hash object that yabeda uses as a key in itsvalueshash, the key is mutated after insertion — its hash code changes, and future lookups can never find it.Fix: Either
MetricEventshould.dupthe attributes hash, orScope#apply_to_telemetryshould work on a copy.Test plan
bundle exec ruby repro.rb— yabeda-only baseline showing bounded growthSENTRY_DSN=... bundle exec ruby repro.rb— shows hash mutation proof (Part 1) and 14x worse growth (Part 2)docker build -t yabeda-repro . && docker run --rm yabeda-repro🤖 Generated with Claude Code