Repository navigation
Uncount dropped in-flight requests so clients don't stall after a reconnect - #556
Conversation
…onnect When a connection drops, disconnect() deletes its in-flight requests, but they stay counted in the client's m_reqs_generated. Nothing processes them, so generated stays ahead of processed for good: - With --reconnect-interval, hold_pipeline() holds once (processed % interval) + (generated - processed) reaches the interval, so after a reconnect the client stops sending. - In cluster mode, the in-flight budget (pipeline * connections) fills up with requests that will never complete. - With --requests, generated reaches the target while processed never does, so the client stops short. In each case the worker's event loop runs out of events. Since #546 the run then fails with "client(s) stopped before reaching their stop condition"; before #546 the worker was silently re-run, which hid this. It is what has failed the nightly soak S4 (test_connection_churn) on master every night since 2026-10-02. Uncount the dropped workload requests: those discarded without --retry-on-error, and those --retry-on-error cannot replay because they have no captured bytes. Requests later dropped from the replay queue are not uncounted here; they may already have been counted as processed when their error reply was queued for retry. dec_reqs_generated() never takes generated below processed, which hold_pipeline() subtracts unguarded. A new is_workload_request() helper classifies request types for both the drain and push_req()'s routed-ops tally. Add a regression test: one client, --reconnect-interval=10 --reconnect-on-error, four CLIENT KILL waves. It fails on master and passes with the fix. It is standalone only: cluster mode rejects --reconnect-interval, and a separate, pre-existing end-of-run hang with reconnects in flight would make a cluster variant flaky. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this, and for the detailed write-up. I traced the accounting and the fix looks right to me. Requests still sitting in the pipeline at
The core change looks solid to me. The two points above are suggestions, not things I'd block the merge on. (would file this as a comment, not a formal block) |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks. Answers in order:
|
Fixes the nightly Soak / Stress failure on master. S4 (
soak/test_connection_churn.py) has failed every night since 2026-10-02.Problem
When a connection drops,
shard_connection::disconnect()deletes its in-flight requests, but they stay counted in the client'sm_reqs_generated. They are never processed, sogenerated − processedstays above the real in-flight count from then on:--reconnect-interval:hold_pipeline()holds once(processed % interval) + (generated − processed)reaches the interval. After a reconnect the client never sends again.pipeline × connections) fills with requests that will never complete.--requests: generated reaches the target while processed never does, so the client stops short.In all three cases the worker's event loop runs out of events and the run fails with
client(s) stopped before reaching their stop condition. Before #546 the worker was silently re-run, which hid this.Fix
--retry-on-error, and those--retry-on-errorcannot replay because they have no captured bytes (enqueue_retry()never takes those, so none was already counted as processed).client::dec_reqs_generated()never takes generated below processed, becausehold_pipeline()subtracts the two without a guard. Onconnections_managerit is pure virtual, like its siblings.is_workload_request()(an exhaustive switch) classifies request types, for both the drain andpush_req()'s routed-ops tally.Testing
test_dropped_in_flight_requests_do_not_stall_client. One client,--reconnect-interval=10 --reconnect-on-error, fourCLIENT KILLwaves. It fails on master and passes with the fix, 3/3 each way locally. Independent runs gave 14/14 failures without the fix and 16/16 passes with it, including TLS. It is standalone only: cluster mode rejects--reconnect-interval, and a separate, pre-existing end-of-run hang (below) would make a cluster variant flaky.-t 8 -c 50 --reconnect-interval=10 --reconnect-on-error, kill every 30 s, 300 s):--reconnect-on-error, kills every 3–5 s):--requestsstopped at 540k of 800k operations.--requestsprocessed exactly 800,000.--requestswith kills, plus pipeline 16 and several reconnect-interval values: master exit 1, fix exit 0 with an exact client-side count. The server may see slightly more commands than requested, at most about pipeline × number of drops, because a request whose reply was lost is generated again. That matches what--retry-on-erroralready does.assert(m_pipeline->size() == 0)on the voluntary reconnect holds under kills every 20–30 ms, with AUTH/SELECT/HELLO setup in flight.Not changed here (follow-ups)
--retry-on-erroraccounting. A request answered with a retryable error is counted as processed, then counted again when its replay completes, so processed can exceed generated. Requests thatdrain_replay_queue_after_reconnect()drops after--max-retriesare not uncounted.replay_request()clearsm_claimed_by_retry, so it isn't possible to tell which dropped replays were already counted. That needs its own fix.--retry-on-error --max-retries=0with kills still fails, on master and with this fix.--test-time, memtier sometimes never exits. Seen on master and with this fix.🤖 Generated with Claude Code
Note
Medium Risk
Changes generated-request accounting on disconnect and reconnect paths, which directly drives pipeline gating and stop conditions; regression-tested but behavior-sensitive for cluster and --requests runs.
Overview
Fixes clients that stop sending after a reconnect when in-flight workload requests were discarded but still counted in
m_reqs_generated, which inflatedgenerated − processedand could wedgehold_pipeline()(e.g.--reconnect-interval), cluster in-flight budgets, and--requestsstop conditions.On
shard_connection::disconnect(), dropped workload requests (plain discard or--retry-on-errorreplays with no captured bytes) now calldec_reqs_generated(), which only reduces the in-flight portion and never lowers generated below processed.is_workload_request()centralizes workload vs connection-setup classification for that drain path and forpush_req()routed-op counting. A standalone regression test kills connections during--reconnect-intervaland asserts the run completes without "stopped before reaching their stop condition".Reviewed by Cursor Bugbot for commit d1fad6e. Bugbot is set up for automated code reviews on this repo. Configure here.