Reproduction for sentry-ruby#2963#46
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d797a29. Configure here.
sentry-junior Bot
added a commit
to getsentry/sentry-ruby
that referenced
this pull request
Jun 8, 2026
Any transport instrumentation that calls Sentry.metrics.* from within transport#send_data re-enters MetricEventBuffer#add_item on the same thread that already holds @Mutex inside send_items, raising: ThreadError: deadlock; recursive locking This includes any non-Yabeda code such as custom transports or other HTTP instrumentation (see getsentry/repro#46 for a minimal repro using a ReentrantTransport that calls Sentry.metrics directly from send_data). Fix: check @mutex.owned? before acquiring in add_item and silently drop the item when the current thread already holds the lock. This is the defensive fix at the correct abstraction level and protects all buffers (MetricEventBuffer, LogEventBuffer) from all callers. The sentry-yabeda Adapter guard (HTTPTransport.sending?) is retained as defense-in-depth and avoids constructing a MetricEvent that will be dropped, but the buffer-level fix is the load-bearing protection. Refs #2963 Refs getsentry/repro#46 Co-Authored-By: junior <[email protected]> Co-authored-by: johdax <[email protected]>
iloveitaly
pushed a commit
to iloveitaly/raven-ruby
that referenced
this pull request
Jun 9, 2026
…etsentry#2964) * fix(yabeda): skip Sentry adapter during own HTTP transport sends MetricEventBuffer uses a non-reentrant Mutex. When HTTP instrumentation (e.g. yabeda-http_requests, yabeda-rails) observes the outgoing Net::HTTP call made by HTTPTransport#send_data, it triggers Sentry::Yabeda::Adapter which calls Sentry.metrics.* -> MetricEventBuffer#add_item on the same thread that already holds the buffer mutex, raising: ThreadError: deadlock; recursive locking Fix: set a thread-local flag (SENTRY_SENDING_KEY) in HTTPTransport for the duration of the do_request call and check it in all Adapter#perform_*! methods, silently skipping metric forwarding for Sentry's own HTTP sends. Fixes getsentry#2963 Co-Authored-By: junior <[email protected]> Co-authored-by: neel <[email protected]> * fix(telemetry): guard add_item against re-entrant mutex acquisition Any transport instrumentation that calls Sentry.metrics.* from within transport#send_data re-enters MetricEventBuffer#add_item on the same thread that already holds @Mutex inside send_items, raising: ThreadError: deadlock; recursive locking This includes any non-Yabeda code such as custom transports or other HTTP instrumentation (see getsentry/repro#46 for a minimal repro using a ReentrantTransport that calls Sentry.metrics directly from send_data). Fix: check @mutex.owned? before acquiring in add_item and silently drop the item when the current thread already holds the lock. This is the defensive fix at the correct abstraction level and protects all buffers (MetricEventBuffer, LogEventBuffer) from all callers. The sentry-yabeda Adapter guard (HTTPTransport.sending?) is retained as defense-in-depth and avoids constructing a MetricEvent that will be dropped, but the buffer-level fix is the load-bearing protection. Refs getsentry#2963 Refs getsentry/repro#46 Co-Authored-By: junior <[email protected]> Co-authored-by: johdax <[email protected]> * test(transport): fix rubocop syntax error in .sending? specs Replace instance_double with []: nil keyword syntax (invalid in Ruby 2.7 parser) with build_fake_response, consistent with the rest of the spec. Co-Authored-By: junior <[email protected]> Co-authored-by: johdax <[email protected]> * refactor(telemetry): simplify re-entrant deadlock fix to single mutex guard Remove the thread-local flag layer (HTTPTransport.sending?, with_sentry_sending, Yabeda adapter sentry_http_sending? checks) in favor of the @mutex.owned? guard in TelemetryEventBuffer alone. This is simpler, more general, and eliminates cross-gem coupling. Also add the guard to flush which had the same exposure. Co-Authored-By: Claude Opus 4.6 <[email protected]> * only guard add_item --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: neel <[email protected]> Co-authored-by: johdax <[email protected]> Co-authored-by: Claude Opus 4.6 <[email protected]>
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.

Reference
getsentry/sentry-ruby#2963
Description
Reproduces the deadlock (
deadlock; recursive locking) and memory leak when bothenable_logsandenable_metricsare enabled in sentry-ruby 6.6.0.The root cause is a re-entrancy bug in
TelemetryEventBuffer: when HTTP instrumentation (e.g. Yabeda) callsSentry.metrics.*duringtransport.send_data, it re-entersMetricEventBuffer#add_itemwhile the flush already holds the non-reentrantMutex.How to run
🤖 Generated with Claude Code