Repository navigation
End a run whose connection setup is rejected instead of hanging (cluster replicas, failover, standalone) - #750
Conversation
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this. I went through the C++ changes and the new tests. The split into "unneeded replica, close it" and "needed connection, end the thread once steady state is reached" makes sense to me, and pulling out
The core fix looks solid, and the tests show the fails-on-master / passes-on-head behaviour this repo likes to see (same idea as the regression test in #364). I'd just like the release note fixed and the (I'd file this as a comment, not a formal block.) |
52f4284 to
4bb84ba
Compare
|
Thanks. Both questions found real problems, and the new commit 4bb84ba fixes them. Q1 (refresh redial): yes, on 1cc026a every CLUSTER SLOTS refresh redialed the closed replica. It was rejected again, counted another connection error and logged both lines again; a run with 6 reshards counted 148 connection errors. The connection is now marked when it is closed, and the replica-redial path in Q2 (failover-promoted node): it did come back through the primary path, and that path was broken. The refresh calls The "carries no requests" wording was wrong for keyless |
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 4bb84ba. Configure here.
dc3b44e to
ee747d9
Compare
|
Follow-up on the review points, at ee747d9:
|
ee747d9 to
8b30858
Compare
|
Thanks. Answers to the points in this review, at 8b30858 (rebased on 6a8099c):
Also in 8b30858: |
…rence primary In cluster mode memtier connects to every replica CLUSTER SLOTS lists, even under the default --read-preference primary, where they carry no request. When a replica rejects AUTH (for example, requirepass is set on the primaries only) and --reconnect-on-error is off, reconnect_after_setup_error() did nothing: the connection stayed open with its setup unfinished, and the replies pipelined behind AUTH were left unparsed, so it kept pending responses. The primaries reach steady state at the same time and disarm --connection-stage-timeout, so nothing ended the run: a --requests run hung after its last request, and a --test-time run waited out the 10 s grace and abandoned the replica connections as clients that got no reply. Close such a connection instead, as a READONLY error already does, and count it as a connection error. The run then ends on the primaries. Other read preferences send reads to the replica, so its rejected setup is still left to --connection-stage-timeout, unchanged. Fixes #737 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The first commit closed a replica connection whose AUTH/SELECT/HELLO was rejected under --read-preference primary. That left two problems: - A failover onto such a replica hung the run, even with --test-time. The slot refresh dials the node as a primary, its AUTH is rejected again, and without --reconnect-on-error reconnect_after_setup_error() left the connection open. The shard's requests then waited forever. The comment said --connection-stage-timeout ends this, but the run had already reached steady state, which disarms it. The same happens to a replica under --read-preference secondary when its AUTH error arrives before the READONLY reply and a SET reaches the primary first. - Every slot refresh redialed the closed replica, which was rejected, counted as a connection error and logged again. Now, without --reconnect-on-error, a rejected setup on a connection that is still needed ends the thread once the run has reached steady state, as a dropped connection does, so the run fails (exit 1). Before steady state it is still left to --connection-stage-timeout (exit 2), and is checked again every second, since another connection reaching steady state disarms the timeout. A replica closed under --read-preference primary is marked and not redialed by slot refreshes until its role changes to primary. The warning no longer says the replica carries no requests: with keyless --command workloads it does, and those requests go to the primaries once it is closed. Fixes #737 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…setup Address review of the setup-rejection path (#737): - Under a read preference other than primary, a rejected replica that was checked after steady state went through attempt_reconnect(), which leaves a connection dead while a peer on the same client is still in its setup. The run then exited 0 without that replica. The connection was rejected, not dropped, and is still needed, so end the thread directly. - Factor the connection-error count, the disconnect-and-count sequence of the READONLY and unneeded-replica paths, and the thread-ending path into helpers. - Check event_add() when arming the re-check timer, and name the right function in its error. - Drop the set_role() reset of the unneeded-replica mark. The mark only affects the replica redial path, and a node a refresh makes a primary is dialed through the primary path anyway. - Move the setup-rejection tests to test_connection_setup_rejected.py and add: a replica rejected while another replica is in its setup (--read-preference secondary), a standalone run where 4 of 16 connections are rejected (it hung on master), and a delayed first reply so the two-primaries test always goes through the re-check timer. Fixes #737 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Once the first rejected connection ends its thread, the run fails and the threads that have not dialed yet never send AUTH, so the server may see fewer than 16 AUTH requests and fewer than 4 rejections (seen under taskset). Assert at least one rejected and one accepted connection instead, and keep the exit code and time bound. Also note at m_setup_rejected_replica that it is never reset. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…error Under --read-preference primary, a replica connection whose setup is rejected is closed because the run does not need it. Such runs exited 0 with no connection errors before this branch; counting it now would break anyone gating on Connection Errors == 0 for a run that went fine. Keep the warning (once per connection, since it is not redialed) and drop the count. Rejected connections that end the thread still count, and the READONLY-off path is unchanged. Also say that m_setup_rejected_context must point to static storage, note that the secondary does-not-hang test only guards against the hang, and widen the 5 s wall-clock bounds to 8 s (all well under the 20 s kill). Co-Authored-By: Claude Opus 5.5 <[email protected]>
8b30858 to
c13ef78
Compare
|
Replies to the review edited at 01:08, at c13ef78 (rebased on 63bc752):
On merge order: #666 has not merged yet, so this lands first, and the description shows how #666 resolves the conflict on top of it. |
|
Replies to the review edited at 01:08 (head unchanged at c13ef78; this pass only edits the description):
|

Problem
When the server rejects a connection setup step (AUTH, SELECT or HELLO) on only some connections, and
--reconnect-on-erroris off, memtier never ends the run.--connection-stage-timeoutdoes not fire.--read-preference primary, replicas reject AUTH (for example,requirepassis set on the primaries only):--requestsrun completes all its requests on the primaries and then hangs.--test-timerun waits out the 10 s grace and then abandons the replica connections as clients that "got no reply to 0 request(s)".--test-time.--read-preference secondary, when the replica's AUTH error is answered before its READONLY reply and a SET reaches the primary first.--requestsrun hangs. This hangs on master and on 2.5.x.Root cause
--reconnect-on-error,reconnect_after_setup_error()did nothing. The rejected connection stayed open with its setup unfinished, never sent a request, and kept its client from ending.--connection-stage-timeoutends such a failure. It does only until any connection, on any thread, reaches steady state:report_connection_stage_success()then disarms the supervisor. That usually happens at the same time, on the connections that were accepted.--read-preference primary.Fix
Without
--reconnect-on-error, a rejected setup step is handled in one of two ways:--read-preference primaryis not needed: keyed requests go to the primaries, and keyless--commandrequests that the replica connection would have sent go to the primaries once it is closed.Connection Errors: 0, as before.--connection-stage-timeout(exit 2). The connection checks again every second, because a connection on another thread reaching steady state disarms that timeout.How totals are computed, and when
--requestsand--test-timestop a run, are unchanged. What changes is the outcome of a run where a connection that is still needed is rejected: a run that used to hang now fails with exit 1. A--test-timerun that used to finish after the 10 s drain grace with exit 0 and incomplete results also exits 1 now. See the release note.Unchanged:
--reconnect-on-errorthe connection reconnects as before.Refactoring:
count_connection_error(),disconnect_after_error()(shared with the READONLY path) andend_thread()(shared withattempt_reconnect()).Options I considered and did not take:
primary. This changes the topology and connection-count output and the role-flip path. It is a separate decision.Release note
Tests
tests/test_connection_setup_rejected.pyis a new file. It reuses the scripted_Nodeand_run()fromtest_cluster_slots_bad_reply.py, extended with:select_error, andauth_reject_first(reject the first N AUTHs, which means N connections);-MOVEDevery N requests, a custom slot map, extra nodes, and a delay before the first data reply;auth_error_with_next, which sends the AUTH error in the same write as the next reply, as a real Redis answering a pipelined setup does.--requests; JSONConnection Errors== 0--test-time=2-MOVEDrefreshes: one AUTH per client,Connection Errors== 0secondary, AUTH error answered alone: exit 1 or 2secondary+ fallback primary, a peer replica in its setup: exit 1-t 4 -c 4 --requests 2000 --connection-stage-timeout 1): exit 1 in under 8 ssecondaryPreferred: replica not closed, exit 2 (pins existing behaviour)taskset -c 2and with RLTest--parallelism 2(4/4 each), and in CI withPARALLELISM=2. RLTest does not run on macOS here.--env oss,MEMTIER_BINARYset).test_cluster_slots_bad_reply,test_cluster_readonly_drop,test_reconnect_late_server_start,test_cluster_failover_retry,test_reconnections,test_read_preference_resp3, andtest_run_count_exit_code(Exit 2 when any --run-count run hits --connection-stage-timeout #752).Real 2+2 cluster (requirepass on the primaries only, dummy password),
-t 2 -c 5 --test-time 8, withCLUSTER FAILOVER FORCEon a replica 3 s in. The failover took effect in about every other run. In the runs where it did:Merge order with #666
#666 conflicts with this PR in
shard_connection.cpp/.handtests/test_cluster_slots_bad_reply.py. To resolve:reconnect_after_setup_error(), keep End a --test-time run at its deadline while reconnecting to a dead server #666's signature and its--reconnect-on-errorbranch, thenreturn, then this PR's two branches._Nodeconstructor parameters.Whichever lands second rebases.
Fixes #737
Affected versions
Cluster: 2.5.0 through 2.5.2 and master. ee757e7 (#456,
--read-preference) made cluster mode connect to replicas.Standalone partial-AUTH hang: the rejected-setup path that leaves the connection open is older (#625), and per the maint lens, 2.5.x hangs too.
Reproduced on master 8ef3971, b1da970 and 63c0009. Per the issue, also reproduced on 2.5.2 f3ff179.
🤖 Generated with Claude Code
Note
Medium Risk
Changes connection lifecycle and thread termination on setup failures across cluster and standalone paths; behavior differs by read preference and steady-state timing, though covered by new integration tests.
Overview
Fixes benchmarks that hang when AUTH/SELECT/HELLO fails on some connections and
--reconnect-on-erroris off. Rejected connections no longer sit in unfinished setup forever (which blocked clients from finishing and disabled--connection-stage-timeoutafter another connection reached steady state).Without reconnect: Under
--read-preference primary, cluster replicas that reject setup are closed and markedis_setup_rejected_replicaso CLUSTER SLOTS refreshes do not redial them repeatedly; the run can still exit 0. Any other needed connection gets a 1s libevent re-check andend_threadonce steady state is reached (exit 1), or stays on--connection-stage-timeoutat startup (exit 2).count_connection_error,disconnect_after_error, andend_threadcentralize error accounting and teardown (including the READONLY no-reconnect path).Tests: New
test_connection_setup_rejected.pyand richer scripted peers intest_cluster_slots_bad_reply.py(pipelined AUTH errors, SELECT failures, periodic -MOVED, partial AUTH rejection).Reviewed by Cursor Bugbot for commit 8b30858. Bugbot is set up for automated code reviews on this repo. Configure here.