Skip to content

Don't count connection rejections as replies - #897

Merged
fcostaoliveira merged 9 commits into
masterfrom
claude/rejection-only-run-894
Oct 26, 2026
Merged

fcostaoliveira merged 9 commits into
masterfrom
claude/rejection-only-run-894

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

-ERR Protocol error:, -ERR max number of clients and -DENIED Redis is running in protected mode refuse 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 --requests or --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-timeout poll 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()):

  • The reply is not handled, answered or processed. It is not an op and cannot complete --requests or --test-time. The request is uncounted, or kept for replay under --retry-on-error, as on a disconnect. That per-request logic is now drop_unanswered_request(), which disconnect() also uses.
  • The connection is dropped through attempt_reconnect(). Without --reconnect-on-error the thread ends with error: server <host> rejected the connection: <reply> and Connection 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-preference other than primary while peers are still in setup: the connection is left dead, as for any drop.
  • Before the connection's first workload reply, the rejection is also a setup failure. It reports a connection-stage failure and does not reset the reconnect budget. With --reconnect-on-error it 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.
  • -ERR Protocol error is caused by the request (e.g. a value above proto-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.
  • After a workload reply, any of the three rejections is a plain drop. A healthy --test-time --reconnect-on-error run whose connection is dropped this way near the deadline ends normally, and a replica that served reads is redialled, as on master.
  • Only top-level error replies are matched. An array's status is the line of its last element, so an array ending in an error with one of these prefixes was matched since Treat ordinary workload errors as connection progress #788.
  • Ordinary -ERR/-NOPERM/-OOM/... workload replies are counted as before (Treat ordinary workload errors as connection progress #788).
  • The README lists the three rejections under the retry and "Reconnecting after connection errors" sections.

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=30 so the supervisor never decides. Expected: exit 1, Count 0, Interrupted true, Connection Errors 1, 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 error and is gone. Under --test-time=3 --reconnect-on-error the run ends normally (exit 0, Count 19). Fails on 41afee4 (exit 1, "Connection setup failed earlier and the run is over").
    • A mutant that only bumps the processed count before the handler (survived round 1) now fails the reconnect case.
    • 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-error the run fails with exit 1 at the deadline. Fails if disconnect() does not forget the earlier replies.
    • test_protocol_error_on_a_new_connection_is_a_drop: after 19 replies, -ERR Protocol error on the connection and again as the first reply after the reconnect, then the server is gone. Under --test-time=3 --reconnect-on-error the 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=2 the run fails (exit 1, Count 0, Interrupted true). Fails if Protocol error were 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 reached under --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 and finished() 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 check passes 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.py and test_cli_fuzz_phase1.py::test_426_8.

Release notes

A run whose replies were connection rejections (-ERR Protocol error, -ERR max number of clients, -DENIED protected mode) no longer reports them as ops or finishes on them. The case users are most likely to notice is a --data-size above the server's proto-max-bulk-len: the error replies used to count in Count and the run could exit 0 (e.g. with --test-time --reconnect-on-error). It now fails as below.

  • Without --reconnect-on-error it fails with exit 1 as soon as the connection is refused.
  • With --reconnect-on-error it fails with exit 1 once --max-reconnect-attempts is exhausted. With the default unlimited attempts it fails with exit 2 after --connection-stage-timeout at startup. Otherwise it keeps reconnecting until the --test-time deadline and then fails with exit 1, or, with --requests, indefinitely, as for a server that is down.
  • A rejection after a connection served replies is a dropped connection, and so is -ERR Protocol error (e.g. a value above proto-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, -DENIED protected mode) are no longer treated as completed workload replies, so a run cannot hit --requests or --test-time with exit 0 while reporting those errors as ops.

shard_connection::handle_connection_rejection() routes top-level rejection errors through drop_unanswered_request() (shared with disconnect()): 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_connect splits 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 call handle_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.

-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]>
@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

🤖 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 --requests was wrong. Moving the per-request logic out of disconnect() into drop_unanswered_request() looks behavior-preserving as far as I can tell, including the retry_on_error with m_replay_queue == NULL case, which still ends up as dropped. The new tests also fail on the old code, which is the bar #364 set for this kind of fix.

  • reconnect_after_setup_error() now calls handle_connection_retired() every time it closes an optional replica. That includes the existing AUTH/SELECT/HELLO rejection path, not just the new A run whose only replies were connection rejections (-ERR Protocol error, max number of clients, -DENIED protected mode) exits 0 and reports them as throughput #894 path. I think that's the right fix there too. But it changes behavior for that path, and the only new test covers a replica rejected on its first read. Did you consider adding a rejected-AUTH replica with --retry-on-error to the same test, or at least saying in the description that it changes too?

  • Just checking the refused predicate in handle_connection_rejection(). m_reply_since_connect is per connection, but get_reqs_answered() is per client. So in cluster mode, an -ERR Protocol error on a fresh shard connection counts as a drop as soon as any other shard has answered. I guess that matches "once the client got a reply," but is it intentional?

  • On compatibility: --data-size above proto-max-bulk-len without --reconnect-on-error used to report the error replies as ops in Count and could exit 0. It now exits 1. That's disclosed in the release notes, and I don't see a less-breaking design that wouldn't keep misreporting, so I'm fine with it. It may still be worth naming the oversized-value case explicitly in the release note, since that's the invocation users are most likely to notice changing.

  • I may be wrong, but handle_connection_retired() runs release_retired_connection() on a replica that stays in the topology. After that, can routing still push cross-shard reads into m_key_index_pools[replica], or does m_setup_rejected_replica keep it out of get_key_for_conn()? The 50-reads test suggests it does, but a second look from whoever owns cluster read-preference routing would help.

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)

fcostaoliveira and others added 4 commits October 26, 2026 04:08
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]>
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

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 -ERR max number of clients reached and closes, then serves +OK. Command: -t 1 -c 1 --requests=10 --retry-on-error --retry-backoff-ms=50.

Case Build rc Count Errors Retry Attempts Retried Ops Connection Errors
--reconnect-on-error, 3 rejections master 4d3edc5 0 10 0 3 1 3
this PR 0 10 0 0 0 3
no reconnect, 1 rejection master 4d3edc5 1 0 2 1 1 1
this PR 1 0 1 0 0 1
  • Retry Attempts and Retried Ops drop because the rejection is no longer classified as a retryable error reply. The request is held for replay on the reconnect, as on any dropped connection. The rejection stays visible in Connection Errors, and in the stderr line rejected the connection.
  • Errors still counts the request when it is abandoned. Without --reconnect-on-error it is 1 here: the rejected request, which was never resent. Master shows 2 because it generated one more request onto the connection before it noticed the close.
  • I added a README paragraph in the retry counters section saying this (c.f. the latest commit).
  • The duplicated dec_reqs_generated / abandon_requests tally: I left it. It is two lines in two call sites, and a helper would only move them.

🤖 Generated with Claude Code

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread shard_connection.cpp Resolved
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]>
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Thanks for the second pass.

  • Exit code: agreed, this is the user-visible part. A run whose replies were all connection rejections used to exit 0 and report them as throughput. It now fails: exit 1, or exit 2 when --reconnect-on-error retries until --connection-stage-timeout. The release notes say so. I don't see a softer option either: Redis closes the connection after these replies, so the old exit 0 was a false success, and whether you got it depended on timing.
  • The two flags: I added the header sentence (853a11e). m_setup_failed_since_reply carries across reconnects until the next reply (Reconnect when AUTH/SELECT/HELLO fails on a reconnect instead of hanging #630). m_reply_since_connect has to start false on every new connection, so it is cleared in disconnect(). test_rejection_on_a_new_connection_is_a_setup_rejection fails if that clear is removed.
  • Unit test: I added a pass without --reconnect-on-error: the request is uncounted, nothing is redialled, and the thread ends. The after-a-reply path would need a test-only setter for the flag. The peer test test_rejection_after_replies_is_a_drop already fails if the !m_reply_since_connect check is dropped, so I left it there.
  • EVAL returning -ERR Protocol error: ...: this is a deliberate tradeoff. In Redis these three texts come only from the request parser and the accept path, and Redis closes the connection right after sending them. Treating such a reply as a drop matches what the server does. A script that returns one of these exact top-level errors is the only case that loses, and it now shows up as a dropped connection instead of an op. An array that only contains such an error is still an ordinary reply; test_array_ending_in_a_rejection_text_is_a_workload_reply covers that.

🤖 Generated with Claude Code

fcostaoliveira and others added 3 commits October 26, 2026 06:05
…ly-run-894

# Conflicts:
#	tests/test_connection_setup_rejected.py
-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]>
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Thanks, (1) was a real false failure. I reproduced it against Redis 8.6 with proto-max-bulk-len 1mb, -t 1 -c 1 --ratio=1:0:

Case master 4d3edc5 2cac5ed 011a57d
mixed --data-size-range=200000-1300000, --test-time=5 --reconnect-on-error rc 0, Count 18 rc 1, Count 10, "failed once the run was over" rc 0, Count 10
same + --retry-on-error rc 0, Count 4 rc 1, Count 4 rc 0, Count 4
same + --retry-on-error --max-reconnect-attempts=3 rc 1 rc 1 rc 1
mixed, --requests=40 --reconnect-on-error rc 0, Count 40 rc 0, Count 40 rc 0, Count 40
all oversized (--data-size=1100000), --requests=3, no reconnect rc 1, Count 1 rc 1, Count 0 rc 1, Count 0
all oversized, --test-time=5 --reconnect-on-error (also with --connection-stage-timeout=0) rc 0, Count 6 rc 1, Count 0 rc 1, Count 0

The Count drop from master (18 to 10) is the intended change: the rejections are no longer ops.

Fixed in 011a57d. -ERR Protocol error is caused by the request, so once the client has had any reply it is a plain drop, even as the first reply on a new connection. It is still a setup failure only for a client that never got a reply. Making it always a plain drop, as suggested, would have turned the all-oversized --test-time --reconnect-on-error run into exit 0 with Count 0: that client never gets a reply, so it simply reaches its deadline. max number of clients and -DENIED keep the before-first-reply setup handling, since they are about the connection.

The --max-reconnect-attempts=3 row fails on master too. The replayed oversized request is the first thing sent on each new connection and is dropped again, so the attempts run out before --max-retries gives up on it.

Tests (tests/test_workload_error_progress.py):

  • test_protocol_error_on_a_new_connection_is_a_drop: -ERR Protocol error after 19 replies and again as the first reply after the reconnect. It ends with exit 0, Count 19; it fails on 2cac5ed (exit 1).
  • test_protocol_error_before_any_reply_fails_the_run: every request is answered with Protocol error. It ends with exit 1, Count 0; it fails if Protocol error is always a plain drop (exit 0).
  • test_rejection_on_a_new_connection_is_a_setup_rejection now uses -ERR max number of clients reached for the rejections after the reconnect, so it still tests the setup path.

(2) No. A replica closed for good stays disconnected and is not redialled as a replica (the main connection and --reconnect-interval recreate connections on their own paths, but not as a read target). Under the replica read preferences, select_target_conn() only picks a replica that passes conn_is_live_for_routing() (is_ready_for_reads(), which requires conn_connected), and so does every other read-routing site. Under primary, reads and writes go to the slot primary. So nothing can be queued onto its key pool after release_retired_connection(). The flush there covers what was queued before it closed; test_replica_rejecting_its_first_read_hands_off_held_requests checks Count 50 with no stranded request.

Nit: I left the accounting as it is. It is two lines at two call sites.

make check passes 18/18. These RLTest files pass: test_workload_error_progress.py (14/14), test_connection_setup_rejected.py (21/21), test_connection_stage_worker_ended.py, test_data_size_pattern_command.py, test_run_count_exit_code.py and test_cli_fuzz_phase1.py::test_426_8.

🤖 Generated with Claude Code

@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Thanks.

  • The rejected-AUTH replica path: yes, handle_connection_retired() now also runs when an optional replica's AUTH/SELECT/HELLO is 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 releases what the replica holds too. I've added that to the description, along with the fact that only the first-read rejection has a test.
  • Per-client get_reqs_answered() in the -ERR Protocol error check: that's intentional. Protocol error is caused by the request, so it tells us nothing about whether that shard accepted the connection. The client-level "no reply yet" condition exists only so that a run where nothing ever succeeds (every value above proto-max-bulk-len) fails instead of ending with exit 0 and Count 0. Once any shard has answered, a Protocol error on another shard's fresh connection is a dropped request on a working setup. max number of clients and -DENIED are about the connection itself, so they keep the per-connection check.
  • Release note: it now names the oversized-value case: a --data-size above proto-max-bulk-len used to count the error replies in Count and could exit 0. It now fails.
  • Routing to the closed replica: as in my previous reply, no. Every read-routing site only picks a replica that is connected (is_ready_for_reads()), and a replica closed for good is not redialled as a replica. So nothing is pushed to its key pool after release_retired_connection(); the 50-reads test checks there is no stranded request.

🤖 Generated with Claude Code

@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Owner review summary for 011a57d: ready to merge.

  • Review: 7 lenses (SEM, OUT, TEST, BUILD, LIFE, INTER, MAINT) all APPROVE at 011a57d. That took 7 rounds; every new head got a 6-lens delta recheck, and BUILD ran on the final CI.
  • CI: 145 passed, 6 skipped (label- or release-gated), 0 failed. Sanitizers are clean across 84 RLTest jobs (16,307 tests). No job is more than +1.6 min slower than on master.
  • Tests:
    • test_workload_error_progress.py (14 cases), test_connection_setup_rejected.py (21) and test_cluster_slots_bad_reply.py (20) pass in all 14 inspected jobs (plain, auth, TLS, cluster, ASAN, TSAN, UBSan, coverage).
    • reconnect_siblings_test passes in 15 jobs.
    • Each new test is shown to fail on master or on the earlier head it covers.
  • Real Redis: the -ERR Protocol error rule was reproduced on Redis 8.6 with proto-max-bulk-len 1mb, by the owner and independently by a reviewer. A mixed-size --test-time --reconnect-on-error run exits 0, and an all-oversized run exits 1, where master exits 0 with the error replies counted as ops.
  • Bugbot: success on 011a57d. Both threads are answered and resolved.
  • Auto-review: answered in my last reply. The description now covers the rejected-AUTH replica path and names the oversized-value case in the release notes.
  • Follow-ups (not blocking):
    • a test for the rejected-AUTH replica release;
    • a rejection after the --test-time deadline has no test;
    • naming and comment nits.
  • Merge note: Re-route staged cluster monitor lines when the slot map changes #885 changes the same retire block in handle_cluster_slots() that this PR moves into release_retired_connection(). Re-route staged cluster monitor lines when the slot map changes #885 will port its changes into the helper when it merges master.

Fixes #894.

🤖 Generated with Claude Code

@fcostaoliveira
fcostaoliveira merged commit 33ff193 into master Oct 26, 2026
151 checks passed
fcostaoliveira added a commit that referenced this pull request Oct 26, 2026
#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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant