Skip to content

.

eec68c4
Select commit
Loading
Failed to load commit list.
Merged

fix(logging): Fix deadlock in log batcher #5684

.
eec68c4
Select commit
Loading
Failed to load commit list.
@sentry/warden / warden completed Mar 17, 2026 in 2m 43s

3 issues

High

Re-entry flag not reset on early return, causing subsequent spans to be silently dropped - `sentry_sdk/_span_batcher.py:65-66`

When _ensure_thread() fails or _flusher is None, the code returns at line 66 after setting self._active.flag = True at line 63, but before entering the try block. This bypasses the finally clause that resets the flag. Once this path is taken, the flag remains True permanently for that thread, causing all subsequent add() calls from the same thread to bail out early at line 60-61. This will result in silent span data loss.

Also found at:

  • sentry_sdk/_batcher.py:117-122

Medium

flush() method lacks re-entry guard, causing protection to be incorrectly reset - `sentry_sdk/_batcher.py:117-122`

The flush() method unconditionally sets self._active.flag = True and resets it to False in the finally block, without first checking if the flag was already set. If flush() is called while _flush_loop() is running on the same thread (which permanently sets _active.flag = True), the finally block will incorrectly reset the flag to False, defeating the deadlock protection. This could allow a subsequent add() call to proceed and attempt to acquire locks that are already held.

Re-entry flag not cleared on early return, permanently dropping all spans from thread - `sentry_sdk/_span_batcher.py:65-66`

When _ensure_thread() returns False or _flusher is None at lines 65-66, the method returns without clearing self._active.flag. Since the flag is set at line 63 before the try block that contains the finally to reset it, this early return path leaves the flag permanently True for the current thread. All subsequent add() calls from that thread will be silently discarded. The base class _batcher.py correctly places this check inside the try block (lines 94-96), ensuring the finally always runs.

4 skills analyzed
Skill Findings Duration Cost
code-review 1 59.6s $0.25
find-bugs 2 2m 2s $0.49
skill-scanner 0 1m 6s $0.12
security-review 0 36.4s $0.18

Duration: 4m 44s · Tokens: 579.0k in / 12.6k out · Cost: $1.07 (+extraction: $0.01, +merge: $0.00, +fix_gate: $0.01, +dedup: $0.00)