Skip to content

fix(logs, metrics): don't recurse when sdk_logger forwards to Sentry and the buffer is full - #3253

Open
pcbeingused33 wants to merge 1 commit into
getsentry:masterfrom
pcbeingused33:fix/telemetry-buffer-drop-log-recursion
Open

pcbeingused33 wants to merge 1 commit into
getsentry:masterfrom
pcbeingused33:fix/telemetry-buffer-drop-log-recursion

Conversation

@pcbeingused33

Copy link
Copy Markdown
Contributor

Fixes #3252

Cause: when a telemetry buffer is full, add_item logs "exceeded max capacity, dropping event" after releasing @mutex. If sdk_logger forwards to Sentry.logger, that message re-enters add_item, is dropped too, logs again, and so on until SystemStackError.

Fix: emit that debug message while still holding the mutex, so the existing @mutex.owned? guard returns early for the re-entrant call. This is the one log call moved back under the lock; it only runs on the drop path, and record_lost_event stays outside.

Tests: a new shared example (run for both the log and metric buffers) makes sdk_logger.debug call add_item again on a full buffer, mirroring the forwarding logger from the issue. Without the change it fails with SystemStackError; with it, the message is logged once and the re-entrant call returns early. spec/sentry/log_event_buffer_spec.rb and spec/sentry/metric_event_buffer_spec.rb pass on Ruby 3.4, and RuboCop passes on the touched files.

This change was prepared with AI assistance.

…and the buffer is full

The drop message was logged after releasing the buffer mutex, so an
sdk_logger that adds telemetry re-entered add_item, dropped again and
logged again until the stack overflowed. Log it while holding the mutex,
so the existing owned? guard stops the re-entrant call.

Fixes getsentry#3252

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@pcbeingused33
pcbeingused33 requested review from a team and solnic as code owners December 1, 2026 00:49
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

PR risk: medium

For commit 8a2b9c7.

Main concerns: reach.

This label is a hint for reviewers, not an approval.

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

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SystemStackError when sdk_logger forwards to Sentry.logger and the log buffer is full (regression in 7.1.0)

1 participant