Repository navigation
Don't count connection rejections as replies - #897
Conversation
-ERR Protocol error, -ERR max number of clients and -DENIED protected mode refuse the connection, not the command: Redis closes it after the reply. #788 already kept them out of steady state, but the reply was still counted as answered and processed, so it could satisfy --requests or --test-time and end the run with exit 0, reporting the rejections as ops. Handle such a reply as a dropped connection instead: the request is uncounted (or kept for replay under --retry-on-error), and the connection reconnects as after a rejected setup step with --reconnect-on-error, or ends its thread without it, so the run fails with exit 1 at once rather than whenever --connection-stage-timeout happens to poll. 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. I went through the shard_connection / cluster_client changes and the tests, and have a few questions below. The core idea makes sense to me. These three replies close the connection, so counting them as ops and letting them satisfy
The fix itself looks solid to me. I'd just like answers on the first two points before this merges. (would file this as a comment, not a formal block) |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A connection that already served a workload reply and then gets -ERR Protocol error (e.g. for an oversized value) was not refused at setup. Handling it as a rejected setup step under --reconnect-on-error failed a healthy --test-time run whenever the reconnect was due at the deadline. Only a rejection before the connection's first reply is a setup rejection now; after a reply it goes through attempt_reconnect() like any drop, so a replica that served reads is also redialled again. Match only top-level error replies: an array's status is its last element. Document the three rejections in the README. Tests: a late rejection under --test-time --reconnect-on-error ends normally; three reconnected rejections do not complete --requests=1; the JSON reports Interrupted and the connection error. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks. On the counters: yes, it is intended. I measured it with a peer that answers the first request on each of the first N connections with
🤖 Generated with Claude Code |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 78dac0f. Configure here.
A replica closed as not needed (a rejected setup step, or a connection rejection before its first reply under --read-preference primary or secondaryPreferred --reconnect-on-error) is never redialled. With --retry-on-error the read it refused stayed in its replay queue, counted as generated but never resent, so a --requests run stopped short and failed. Release it as a slot map refresh releases a retired connection: the staged and cross-shard queued requests are uncounted, the held requests are handed to the slot primary, and the producers are woken. The retire loop in handle_cluster_slots() now uses the same helper. Also explain why m_reply_since_connect is not m_setup_failed_since_reply, and add a unit pass for a rejection without --reconnect-on-error. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for the second pass.
🤖 Generated with Claude Code |
…ly-run-894 # Conflicts: # tests/test_connection_setup_rejected.py
Co-Authored-By: Claude Opus 5.5 <[email protected]>
-ERR Protocol error is caused by the request, e.g. a value above proto-max-bulk-len, not by the connection. As the first reply on a new connection it was handled as a rejected setup step, so a --test-time --reconnect-on-error run whose oversized value happened to be first after a reconnect failed at the deadline (#630), where master ended it normally. Only a client that never got a reply still treats it as a setup failure, so an all-oversized run still fails instead of ending with exit 0 and Count 0. -ERR max number of clients and -DENIED keep the setup handling before a connection's first reply. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks, (1) was a real false failure. I reproduced it against Redis 8.6 with
The Count drop from master (18 to 10) is the intended change: the rejections are no longer ops. Fixed in 011a57d. The Tests (
(2) No. A replica closed for good stays disconnected and is not redialled as a replica (the main connection and Nit: I left the accounting as it is. It is two lines at two call sites.
🤖 Generated with Claude Code |
|
Thanks.
🤖 Generated with Claude Code |
|
Owner review summary for 011a57d: ready to merge.
Fixes #894. 🤖 Generated with Claude Code |
#897 moved the retire body into release_retired_connection() and added handle_connection_retired(). Both connection hooks are kept. The helper now carries this branch's retire path: it clears the awaiting-redial mark before disconnect(), re-routes staged monitor lines instead of flushing them (only a replica retired by the hook can still hold any, and none do today), and keeps the key-pool uncount and the replay hand-off. Co-Authored-By: Claude Opus 5.5 <[email protected]>

Problem
-ERR Protocol error:,-ERR max number of clientsand-DENIED Redis is running in protected moderefuse the connection, not the command: Redis closes it after the reply. #788 keeps them out of steady state, but the reply was still counted as answered and processed. A run whose only replies were rejections could reach--requestsor--test-time, exit 0 and report the rejections as Sets ops/sec, with"Interrupted": "false"and"Connection Errors": 0. Whether it got 0 or 2 depended on whether the--connection-stage-timeoutpoll happened to run first (#894).Change
A top-level rejection reply to a workload request is handled as a dropped connection (
shard_connection::handle_connection_rejection()):--requestsor--test-time. The request is uncounted, or kept for replay under--retry-on-error, as on a disconnect. That per-request logic is nowdrop_unanswered_request(), whichdisconnect()also uses.attempt_reconnect(). Without--reconnect-on-errorthe thread ends witherror: server <host> rejected the connection: <reply>andConnection rejected by the server and --reconnect-on-error is not set, ending this thread., and the run fails with exit 1 without waiting for the supervisor's poll. The exception is the existing case under--read-preferenceother than primary while peers are still in setup: the connection is left dead, as for any drop.--reconnect-on-errorit is handled like a rejected AUTH/SELECT/HELLO (reconnect_after_setup_error()), so a run that is over before the server accepts the connection fails.--read-preference primaryorsecondaryPreferredwith--reconnect-on-error, a replica connection rejected before its first reply is closed as unneeded, as for a rejected AUTH.handle_cluster_slots()intocluster_client::release_retired_connection(), which both paths use (connections_manager::handle_connection_retired()). The hook also runs on the existing path for an optional replica whose AUTH/SELECT/HELLO was rejected (--reconnect-on-error with unlimited --max-reconnect-attempts: run never ends when the server stays down, even past --test-time #656/Cluster --requests run hangs forever when AUTH fails on a replica connection (replica has no password); --connection-stage-timeout does not fire #737), so that path now releases what the replica holds too. Only the first-read rejection has a test.-ERR Protocol erroris caused by the request (e.g. a value aboveproto-max-bulk-len), not by the connection: once the client got any reply it is a plain drop, even as the first reply on a new connection. Only a client that never got a reply treats it as a setup failure, so an all-oversized run still fails instead of ending with exit 0 and Count 0.--test-time --reconnect-on-errorrun whose connection is dropped this way near the deadline ends normally, and a replica that served reads is redialled, as on master.-ERR/-NOPERM/-OOM/... workload replies are counted as before (Treat ordinary workload errors as connection progress #788).Tests
tests/test_workload_error_progress.py:test_connection_rejections_do_not_complete_the_run: a scripted peer answers with each of the three rejections. It either closes after the reply (--requests=1) or keeps the connection open (--requests=5,--test-time=2), with--connection-stage-timeout=30so the supervisor never decides. Expected: exit 1, Count 0,Interruptedtrue,Connection Errors1, one connection, one reply. With--reconnect-on-error --max-reconnect-attempts=2 --requests=1, the three rejections must not complete the run: exit 1, Count 0, three connections. Fails on master (exit 0, Count 1 / 5).test_rejection_after_replies_is_a_drop: after 19 replies the peer sends one-ERR Protocol errorand is gone. Under--test-time=3 --reconnect-on-errorthe run ends normally (exit 0, Count 19). Fails on 41afee4 (exit 1, "Connection setup failed earlier and the run is over").test_array_ending_in_a_rejection_text_is_a_workload_reply: an array reply ending in-ERR Protocol error: ...is an op (--requests=5: exit 0, Count 5). Fails without the top-level-only guard.test_rejection_on_a_new_connection_is_a_setup_rejection: after its replies the connection is rejected (a drop), and every reconnect is refused at its first request with-ERR max number of clients reached. Under--test-time=3 --reconnect-on-errorthe run fails with exit 1 at the deadline. Fails ifdisconnect()does not forget the earlier replies.test_protocol_error_on_a_new_connection_is_a_drop: after 19 replies,-ERR Protocol erroron the connection and again as the first reply after the reconnect, then the server is gone. Under--test-time=3 --reconnect-on-errorthe run ends normally (exit 0, Count 19). Fails on 2cac5ed (exit 1).test_protocol_error_before_any_reply_fails_the_run: every request gets-ERR Protocol error; with--reconnect-on-error --connection-stage-timeout=0 --test-time=2the run fails (exit 1, Count 0, Interrupted true). Fails ifProtocol errorwere always a plain drop (exit 0).tests/test_connection_setup_rejected.py::test_replica_rejecting_its_first_read_hands_off_held_requests: a scripted cluster replica answers its first read with-ERR max number of clients reachedunder--requests=50 --ratio=0:1 --read-preference=secondaryPreferred --reconnect-on-error --retry-on-error. Expected: exit 0, 50 reads on the primary, Count 50. Fails on 78dac0f (exit 1, 0 primary reads: the held read was never resent).tests/unit/reconnect_siblings_test.cpp:handle_connection_rejection()leaves answered and processed at 0 andfinished()false. It uncounts the request or keeps it for replay, arms a reconnect and marks the setup failed since the last reply. Without--reconnect-on-error, the request is uncounted, nothing is redialled and the thread ends.make checkpasses 18/18. These RLTest files pass:test_workload_error_progress.py,test_connection_setup_rejected.py,test_connection_stage_worker_ended.py,test_cluster_slots_bad_reply.py,test_run_count_exit_code.py,test_data_size_pattern_command.py,test_json_fatal_error.py,test_reconnect_late_server_start.pyandtest_cli_fuzz_phase1.py::test_426_8.Release notes
A run whose replies were connection rejections (
-ERR Protocol error,-ERR max number of clients,-DENIEDprotected mode) no longer reports them as ops or finishes on them. The case users are most likely to notice is a--data-sizeabove the server'sproto-max-bulk-len: the error replies used to count inCountand the run could exit 0 (e.g. with--test-time --reconnect-on-error). It now fails as below.--reconnect-on-errorit fails with exit 1 as soon as the connection is refused.--reconnect-on-errorit fails with exit 1 once--max-reconnect-attemptsis exhausted. With the default unlimited attempts it fails with exit 2 after--connection-stage-timeoutat startup. Otherwise it keeps reconnecting until the--test-timedeadline and then fails with exit 1, or, with--requests, indefinitely, as for a server that is down.-ERR Protocol error(e.g. a value aboveproto-max-bulk-len) once the client got any reply.Affected versions
Counting these replies as ops dates to the original code, so the exit-0 result exists in every release. Since 2e8869e (#431) these replies are also classified as connection-stage failures, so since then the exit-0 result contradicts the supervisor.
git tag --contains 2e8869e: 2.4.0, 2.4.1, 2.4.2, 2.4.3, 2.4.4, 2.5.0, 2.5.1, 2.5.2. 77975b0 (#788, master only) narrowed the class to these three prefixes.Fixes #894
🤖 Generated with Claude Code
Note
Medium Risk
Changes core connection/response accounting and run completion semantics for three Redis error prefixes; cluster replica handoff affects read routing under secondaryPreferred with retry/reconnect.
Overview
Fixes #894: Redis connection rejections (
-ERR Protocol error:,-ERR max number of clients,-DENIEDprotected mode) are no longer treated as completed workload replies, so a run cannot hit--requestsor--test-timewith exit 0 while reporting those errors as ops.shard_connection::handle_connection_rejection()routes top-level rejection errors throughdrop_unanswered_request()(shared withdisconnect()): the in-flight request is uncounted or queued for replay under--retry-on-error, and the connection is dropped/reconnected like any other loss.m_reply_since_connectsplits setup rejection (before the first workload reply, same rules as failed AUTH/SELECT) from a late rejection after the connection was already serving traffic.In cluster mode, retiring a connection’s cleanup moves into
release_retired_connection(); optional replicas closed after an early rejection callhandle_connection_retired()so held reads are handed off to the primary (with--retry-on-error), matching slot-map retirement behavior.README documents rejection vs retry counters and read-preference/reconnect edge cases; tests cover scripted rejections, replica handoff, and top-level-only matching.
Reviewed by Cursor Bugbot for commit 2cac5ed. Bugbot is set up for automated code reviews on this repo. Configure here.