Skip to content

Reproduction for sentry-ruby yabeda-memory-growth#47

Merged
sl0thentr0py merged 1 commit into
mainfrom
repro/sentry-ruby-yabeda-memory-growth
Jun 9, 2026
Merged

Reproduction for sentry-ruby yabeda-memory-growth#47
sl0thentr0py merged 1 commit into
mainfrom
repro/sentry-ruby-yabeda-memory-growth

Conversation

@dingsdax

@dingsdax dingsdax commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Reproduces the memory growth from sentry-ruby#2963 (post-deadlock-fix)
  • Discovers a bug in sentry-ruby: Scope#apply_to_telemetry mutates the caller's attributes hash in-place, which corrupts hash keys in yabeda's metric.values (Concurrent::Hash)
  • Every metric increment creates a new orphaned entry — values hash grows linearly with call count instead of being bounded by unique tag combinations
  • With sentry-yabeda: active_record_instantiation_total shows 2005 entries for 50 unique kinds (should be 50). RSS growth is 14x worse (+21 MB vs +1.5 MB)

Root cause

MetricEvent#initialize stores the caller's attributes hash by reference (@attributes = attributes || {}). Then Scope#apply_to_telemetry adds sentry-specific keys (sentry.sdk.name, sentry.sdk.version, sentry.environment, server.address) directly onto this hash. Since sentry-yabeda passes the same hash object that yabeda uses as a key in its values hash, the key is mutated after insertion — its hash code changes, and future lookups can never find it.

Fix: Either MetricEvent should .dup the attributes hash, or Scope#apply_to_telemetry should work on a copy.

Test plan

  • Run bundle exec ruby repro.rb — yabeda-only baseline showing bounded growth
  • Run SENTRY_DSN=... bundle exec ruby repro.rb — shows hash mutation proof (Part 1) and 14x worse growth (Part 2)
  • Alternatively, use Docker: docker build -t yabeda-repro . && docker run --rm yabeda-repro

🤖 Generated with Claude Code

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>
@sl0thentr0py sl0thentr0py merged commit 2fe1a50 into main Jun 9, 2026
13 checks passed
@sl0thentr0py sl0thentr0py deleted the repro/sentry-ruby-yabeda-memory-growth branch June 9, 2026 13:36
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