ref(batcher): Only flush the bucket that triggered the flush event #6168
1 issue
find-bugs: Found 1 issue (1 high)
High
Full flush raises RuntimeError due to dict mutation during iteration - `sentry_sdk/_span_batcher.py:159-205`
When _flush() is called with trace_id=None (e.g. during SDK shutdown or manual sentry_sdk.flush()), buckets is assigned self._span_buffer.keys(), which is a live view over the dict. The loop then executes del self._span_buffer[trace_id] on line 204, mutating the dict while iterating its key view. Python raises RuntimeError: dictionary changed size during iteration, so any full flush with more than one bucket will crash and spans will be lost (and not captured) — directly breaking the documented shutdown/manual-flush path the PR claims to preserve.
Duration: 1m 25s · Tokens: 138.6k in / 4.9k out · Cost: $0.86
Annotations
Check failure on line 205 in sentry_sdk/_span_batcher.py
sentry-warden / warden: find-bugs
Full flush raises RuntimeError due to dict mutation during iteration
When `_flush()` is called with `trace_id=None` (e.g. during SDK shutdown or manual `sentry_sdk.flush()`), `buckets` is assigned `self._span_buffer.keys()`, which is a live view over the dict. The loop then executes `del self._span_buffer[trace_id]` on line 204, mutating the dict while iterating its key view. Python raises `RuntimeError: dictionary changed size during iteration`, so any full flush with more than one bucket will crash and spans will be lost (and not captured) — directly breaking the documented shutdown/manual-flush path the PR claims to preserve.