DeepSeek V4.1 Flash · 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
2 of 2
Comments published
9
Comments matching a bug
2
Comments not matching
7
Cost of this PR
$0.272

Published comments (9)

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

Per-shard buffers multiply global max-flush-segments limit by process count — With N shard processes, each shard now admits ~N× the segments per cycle, so aggregate flush capacity reaches ~N × `spans.buffer.max-flush-segments` and `any_shard_at_limit` fires late, letting the queue overrun its bound. Keep the divisor global by passing the total assigned shard count to the buffer so the limit stays cluster-wide.

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

Spans flusher queries cluster memory once per buffer in submit — `get_memory_info()` fans out a cluster-wide `INFO` to every master regardless of `assigned_shards`, so `submit` issues one round trip per buffer and the summed totals are the same numbers counted N times. Query memory once per `submit` and reuse it across buffers.

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

Unhealthy flusher process is never killed due to isinstance guard — The guard never matches a `SpawnProcess`, so a hung flusher is never killed and its replacement races the old one on the same shard queues, duplicating segments and leaving orphans. Drop the `isinstance` guard or test against `multiprocessing.process.BaseProcess`.

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

Flusher wait_produce timer uses inconsistent "shards" metric tag — The sibling `spans.buffer.flusher.produce` and `spans.buffer.segment_size_bytes` timers tag this same value as `shard`, so dashboards grouping on one shard tag silently miss this metric. Use `{"shard": shard_tag}` for consistency.

mediumbugsrc/sentry/spans/consumers/process/flusher.py:241-245

flusher_unhealthy tags shard with bare int instead of shard_tag — Every other emit site tags `shard` with `shard_tag`, the comma-joined group, so this metric's bare int lives in a different value domain and per-shard grouping can never match. Emit `shard_tag` here or use one identifier at all sites.

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

Assertion does not verify shard distribution across flusher processes — The sum equals 4 for any assignment of the shards, so the test passes even if round-robin placed them all in one process. Assert the per-process counts, e.g. sorted lengths equal `[2, 2]`.

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

Deadline break in join() leaves flusher processes alive — When the deadline expires, the `break` skips the `terminate()` for that process and every remaining one, leaving hung flushers running after `join()` returns. Move the terminate outside the deadline break so all spawned processes are killed on shutdown.

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

Sleep after drift change is a no-op due to patched time.sleep — `time.sleep` is patched to a no-op at line 15, so this returns immediately and provides none of the synchronization the comment claims, running the assertion before post-drift processing finishes. Synchronize on a real condition or remove the misleading sleep.

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

max_processes truthiness mishandles 0 and negative values — Truthiness treats a configured `0` as unset, silently running one process per shard instead of failing fast, while a negative value passes here and later raises `KeyError` on `process_to_shards_map`. Use an explicit None check and reject values below 1.

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.
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 (0)

None.