fix(logging): Fix deadlock in log batcher #5684
1 issue
find-bugs: Found 1 issue (1 medium)
Medium
flush() clobbers re-entrancy guard without checking existing state - `sentry_sdk/_batcher.py:117-122`
The flush() method unconditionally sets _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 another method (like add()) has already set the flag on the same thread, the finally block will incorrectly clear the flag, defeating the re-entrancy protection for the remaining code in the outer method. This could allow a subsequent re-entrant add() call to pass the guard check when it should be blocked.
Also found at:
sentry_sdk/_span_batcher.py:65-66
Duration: 1m 57s · Tokens: 87.9k in / 5.2k out · Cost: $0.24 (+extraction: $0.01, +merge: $0.00)
Annotations
Check warning on line 122 in sentry_sdk/_batcher.py
sentry-warden / warden: find-bugs
flush() clobbers re-entrancy guard without checking existing state
The `flush()` method unconditionally sets `_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 another method (like `add()`) has already set the flag on the same thread, the finally block will incorrectly clear the flag, defeating the re-entrancy protection for the remaining code in the outer method. This could allow a subsequent re-entrant `add()` call to pass the guard check when it should be blocked.
Check warning on line 66 in sentry_sdk/_span_batcher.py
sentry-warden / warden: find-bugs
[MHU-N43] flush() clobbers re-entrancy guard without checking existing state (additional location)
The `flush()` method unconditionally sets `_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 another method (like `add()`) has already set the flag on the same thread, the finally block will incorrectly clear the flag, defeating the re-entrancy protection for the remaining code in the outer method. This could allow a subsequent re-entrant `add()` call to pass the guard check when it should be blocked.