DeepSeek V4 Pro · Heavy

span-buffer-multiprocess-enhancement-with-health-monitoring-sentry

Sentry · Python · M · 100–299 lines · 4 files

The generalist plus 9 specialist lens agents in parallel, then the same verify and dedup steps. Judge: Claude Opus 5.5.

Gold bugs found
2 of 4
Comments published
7
Comments matching a bug
2
Comments not matching
5
Cost of this PR
$1.216

Published comments (7)

highbugsrc/sentry/spans/consumers/process/flusher.py:92-93

Per-process shard buffers bypass global max-flush-segments burst cap — Each process computes its per-shard cap from its own subset size, so with `--flusher-processes N` the total flush grows to roughly `N * max_flush_segments`, defeating the global cap. Derive the cap from the total assigned shard count across `process_to_shards_map` so aggregate volume stays constant.

mediumperformancesrc/sentry/spans/consumers/process/flusher.py:299-301

Redundant get_memory_info loops issue one Redis INFO per buffer per submit — `get_memory_info()` returns cluster-wide usage for any shard subset, so the loop issues a full `INFO` scan once per buffer on every `submit` and scales with `flusher_processes`. Compute the memory info once and reuse it; the `used`/`available` ratio is invariant.

mediumbugsrc/sentry/spans/consumers/process/flusher.py:199

Inconsistent shard tag key on spans.buffer.flusher.wait_produce — This splits the same shard dimension across `shards` and `shard`, so `wait_produce` disappears from any query filtering on `shard`. Use `shard` for consistency with the other flusher metrics.

mediumbugsrc/sentry/spans/consumers/process/flusher.py:51

Explicit max_processes=0 conflated with None in `or` fallback — Passing `0` silently becomes `len(buffer.assigned_shards)` because `or` conflates zero with `None`, launching far more processes than requested. Use an explicit `is None` check and reject values below 1 before computing `num_processes`.

mediumbugtests/sentry/spans/consumers/process/test_consumer.py:60-62

Patched time.sleep no-op causes test to race with flusher thread — The wait returns immediately because the patched `time.sleep` is a no-op, so the assertion still races with the flusher thread. Synchronize on a condition or poll for `messages` with a real deadline instead of sleeping.

mediumbugtests/sentry/spans/consumers/process/test_consumer.py:119-121

Test assertion does not verify shards are distributed across processes — The total only proves no shard was lost; assigning all four to one process would still pass. Assert that every entry in `process_to_shards_map` is non-empty or check the exact expected mapping.

mediumbugsrc/sentry/spans/consumers/process/flusher.py:253-257

SpawnProcess not killed due to isinstance check for multiprocessing.Process — `SpawnProcess` is a `BaseProcess`, not `multiprocessing.Process`, so this guard is always false and hung processes are never killed before a replacement starts. Check `multiprocessing.process.BaseProcess` so `kill()` actually runs and orphans are not left flushing the same shards.

Gold bugs found (2)

highThe restart path only kills a hung flusher if it is a multiprocessing.Process, but spawn-context workers are SpawnProcess, so hung processes are never killed and a duplicate flusher is started for the same shards.
mediumsubmit() queries cluster-wide Redis memory once per flusher buffer, repeating identical INFO calls per process on every submit.

Gold bugs missed (2)

mediumjoin() breaks out of the per-process loop when the shared deadline expires, skipping termination of the remaining flusher processes and leaving them running after shutdown.
medium_ensure_processes_alive only kills the old flusher when isinstance(process, multiprocessing.Process), but it always starts a replacement. A hung thread-based flusher, and even a spawn-context process (SpawnProcess is not a multiprocessing.Process subclass), keeps running beside the new one, so both flush and produce the same shards' segments and duplicate output.