fix(logging): Fix deadlock in log batcher #5684
1 issue
find-bugs: Found 1 issue (1 medium)
Medium
Re-entry guard flag can be clobbered when flush() is called during add() execution - `sentry_sdk/_batcher.py:117-122`
The flush() method unconditionally sets _active.flag = True and then resets it to False in its finally block. If flush() is called while add() is already executing on the same thread (e.g., via a callback triggered during _ensure_thread() or buffer operations), the finally block in flush() will reset the flag to False while add() is still running. This breaks the re-entry guard for the remainder of add()'s execution, allowing a subsequent re-entrant call to proceed and potentially cause the deadlock this PR aims to prevent.
Duration: 1m 37s · Tokens: 100.6k in / 4.2k out · Cost: $0.27 (+extraction: $0.01)
Annotations
Check warning on line 122 in sentry_sdk/_batcher.py
sentry-warden / warden: find-bugs
Re-entry guard flag can be clobbered when flush() is called during add() execution
The `flush()` method unconditionally sets `_active.flag = True` and then resets it to `False` in its finally block. If `flush()` is called while `add()` is already executing on the same thread (e.g., via a callback triggered during `_ensure_thread()` or buffer operations), the `finally` block in `flush()` will reset the flag to `False` while `add()` is still running. This breaks the re-entry guard for the remainder of `add()`'s execution, allowing a subsequent re-entrant call to proceed and potentially cause the deadlock this PR aims to prevent.