fix(logging): Fix deadlock in log batcher #5684
1 issue
find-bugs: Found 1 issue (1 medium)
Medium
flush() missing re-entry guard check - `sentry_sdk/_batcher.py:117-122`
The flush() method sets _active.flag = True without first checking if it's already set. Unlike add() which guards with if getattr(self._active, "flag", False): return None, flush() unconditionally sets the flag and proceeds. If _flush() triggers a GC warning that routes back through the logging integration to flush() (instead of add()), the nested flush() will execute, and its finally block will set _active.flag = False prematurely, leaving subsequent re-entrant calls unprotected.
Duration: 1m 46s · Tokens: 202.4k in / 7.7k out · Cost: $0.42 (+extraction: $0.01)
Annotations
Check warning on line 122 in sentry_sdk/_batcher.py
sentry-warden / warden: find-bugs
flush() missing re-entry guard check
The `flush()` method sets `_active.flag = True` without first checking if it's already set. Unlike `add()` which guards with `if getattr(self._active, "flag", False): return None`, `flush()` unconditionally sets the flag and proceeds. If `_flush()` triggers a GC warning that routes back through the logging integration to `flush()` (instead of `add()`), the nested `flush()` will execute, and its finally block will set `_active.flag = False` prematurely, leaving subsequent re-entrant calls unprotected.