MiniMax M3 · 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 Haiku 5.5.

Gold bugs found
1 of 2
Comments published
7
Comments matching a bug
1
Comments not matching
6
Cost of this PR
$0.300

Published comments (7)

mediumbugsrc/sentry/spans/consumers/process/flusher.py:336-347

SpanFlusher.join leaks orphaned flusher processes when the deadline expires mid-loop — Each unvisited `process` after the deadline holds Redis connections and KafkaProducer clients until the parent exits. Split the loop so all `multiprocessing.Process` instances are terminated in a second pass over `self.processes.values()`.

mediumbugsrc/sentry/spans/consumers/process/flusher.py:126-131

Unused _create_process_for_shard misroutes single shard to whole-process restart — `_create_process_for_shard` has no callers and routes a single shard through `_create_process_for_shards`, misusing a whole-process restart. Wire it into the per-shard restart path or delete the dead helper.

mediumperformancesrc/sentry/spans/consumers/process/flusher.py:298-303

Avoid calling get_memory_info() once per local SpansBuffer; they share cluster client — Repeating `buffer.get_memory_info()` per entry multiplies `cluster.info()` traffic across shared `SpansBuffer` clients. Call it once from a single buffer (e.g., `next(iter(self.buffers.values()))`) and reuse the result.

mediumbugsrc/sentry/spans/consumers/process/flusher.py:185-200

wait_produce timer uses tag key `shards` while sibling metrics use `shard` — The `spans.buffer.flusher.wait_produce` timer tags with `"shards"` while the other three metric sites use `"shard"`, silently splitting the dashboard series. Change `tags={"shards": shard_tag}` to `tags={"shard": shard_tag}` for that timer.

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

Use `is None` instead of truthiness check for max_processes default — `max_processes or len(buffer.assigned_shards)` silently rewrites an explicit 0 into the shard count. Use `max_processes is None` to keep 0 as a real value and constrain the CLI option with a minimum.

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

Flusher shard distribution test only checks total count — Asserting only `total_shards == 4` lets a regression like `process_index = 0` starve a process while passing. Require every `process_to_shards_map` list to be non-empty and balanced within one shard.

mediumbugsrc/sentry/spans/consumers/process/flusher.py:86-93

SpansBuffer flush shard_factor uses per-process shard count instead of global — `shard_factor = max(1, len(self.assigned_shards))` is computed per process, so `max_flush_segments` multiplies by `num_processes`. Either divide by the global `len(buffer.assigned_shards)` or document that the setting is now per-process.

Gold bugs found (1)

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.

Gold bugs missed (1)

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.