fix: recover from total-cluster outages longer than delivery.timeout.ms#48
Merged
Conversation
A producer whose entire cluster becomes unreachable (TCP broken) for longer than delivery.timeout.ms wedged permanently: produced/acked froze and the delivery futures for buffered records hung forever, even after the cluster fully recovered and ready batches were still buffered. Root cause: the background sender loop treated ANY error from its drive pass as fatal and parked the loop (SenderLoopWait::Parked). During a total outage the synchronous pre-dispatch step (metadata fetch) raises a wire Timeout, which parked the loop; a parked loop only wakes on an append or a dispatch completion, and once the producer's appends dry up (buffer full / bounded in-flight window) with no in-flight dispatch, nothing ever wakes it again. - background_loop now retries on a transient drive error (retry.backoff .ms) instead of parking, mirroring Kafka Sender.runOnce which swallows a per-iteration failure and loops. The decision is extracted into resolve_background_loop_wait and unit-tested. - drive_wake_until_waiting's per-iteration reap now uses the pump policy that swallows a per-batch Delivered(Err) (e.g. a post-outage DeliveryTimeout the dispatch task already surfaced on the futures) instead of propagating it and parking; it also no longer drops later Requeue results in the same reap batch.
Add env knobs to soak_bench so a total-cluster outage can be forced past delivery.timeout.ms in seconds under buffer pressure — the condition that wedged the producer: - KACRAB_SOAK_DELIVERY_TIMEOUT_MS / KACRAB_SOAK_REQUEST_TIMEOUT_MS shrink the delivery/request deadlines - KACRAB_SOAK_BUFFER_MEMORY shrinks buffer.memory so it fills fast - KACRAB_SOAK_INFLIGHT_CAP lowers the delivery-future cap so the produce loop blocks (appends dry up) quickly once deliveries stall - KACRAB_SOAK_IDEMPOTENCE toggles enable.idempotence (ruled it out) All default to the prior values, so existing runs are unchanged.
pirumu
added a commit
that referenced
this pull request
Jul 7, 2026
The overnight soak report's F3 finding guessed "delivery.timeout.ms not enforced" — wrong. Add a Resolution section: F3 fixed + verified (PR #48 core, #47 partial) with the traced root cause (background loop parked on a transient metadata Wire(Timeout) and never woke once appends dried up); F1/F4 fixed in code by #47 pending a fresh compound soak; F2 still open. Preserves the historical run data; only appends the post-run resolution.
This was referenced Jul 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug (P1)
A producer whose entire cluster becomes unreachable (TCP broken —
docker stop, notpause) for longer thandelivery.timeout.mswedges permanently:produced/ackedfreeze and the delivery futures for buffered records hang forever, even after the cluster fully recovers with ready batches still buffered.Ruled out (all recover fine): idempotence on/off; outages ≤
delivery.timeout.ms; TCP-preserving outages of any length (docker pause).Root cause
The background sender loop treated any error from its drive pass as fatal and parked the loop (
SenderLoopWait::Parked). During a total outage the synchronous pre-dispatch step (metadata fetch) raises a wireTimeout; that parked the loop. A parked loop only wakes on an append or a dispatch completion — and once the producer's appends dry up (buffer full / bounded in-flight window) with no in-flight dispatch, nothing ever wakes it again.Captured directly with a wedge trace:
→ loop parks with ready batches buffered, brokers already back, and never runs again.
The fix
background_loopretries on a transient drive error (backoff viaretry.backoff.ms) instead of parking forever — mirroring KafkaSender.runOnce, which swallows a per-iteration failure and loops. The decision is extracted intoresolve_background_loop_waitand unit-tested.drive_wake_until_waiting's per-iteration reap now uses the pump policy that swallows a per-batchDelivered(Err)(e.g. a post-outageDeliveryTimeoutthe dispatch task already surfaced on the futures) instead of propagating it and parking; it also no longer drops laterRequeueresults in the same reap batch. (Complementary correctness fix; the same class as fix: recover from broker outages instead of wedging the client #47 but on the loop's top-of-iteration reap.)No per-record or per-iteration scan is added, so no expiry-sweep-style hot-path cost — the earlier hypothesis of needing a Java-style
expiredBatchessweep was wrong; the dispatch task's own delivery-timeout checks are sufficient once the loop stops parking.Validation
Deterministic soak repro (total 3-broker stop >
delivery.timeout.msunder buffer pressure):103104 acked + 2146 expired = 105250 produced— every record resolved; production resumes at the target rate after recovery.make fmt-check,make clippy(-D warnings),make test(--workspace --all-features),make deny— all greenbackground_loop_retries_on_transient_drive_error_instead_of_parking,background_loop_reap_swallows_per_batch_delivery_errorproducer_mock_bench: 5.31M msg/s (10 B), 708 MiB/s (10 KiB) — no regression to the shared dispatch pathSecond commit adds env knobs to
soak_bench(delivery/request timeout,buffer.memory, in-flight cap, idempotence toggle) so this class of outage is reproducible in ~2 min; all default to prior values.