Repository navigation
Send ASKING before resending a request after -ASK - #600
Conversation
|
🤖 Automated first-pass review. A human maintainer still needs to review this before merge. Thanks for this, and for the detailed description. I went through the diff and the surrounding retry and reconnect code. The core fix looks right to me:
The new test also covers the bar from #364: it fails on master (575–782
Since this changes cluster routing, it may be worth a second look from whoever owns the cluster client. Otherwise this looks good to me once the drain-timer question is answered. |
|
Thanks for the review. I pushed 42b5262. It also fixes the red Test OSS-CLUSTER API: TCP TLS job, which turned out to be about your first point. The CI failure (TLS). The address lookup was fine. Under TLS, the ASK reply and CLUSTER SLOTS both give Fix: accept a target that is still connecting (any state except Your points:
On Bugbot's "TLS cluster MIGRATE will fail": it doesn't. RLTest starts TLS cluster nodes with Verification of the new head (local, ports 20200–20219):
These also pass with 42b5262: 🤖 Generated with Claude Code |
42b5262 to
606c168
Compare
|
Pushed 606c168. The branch is rebased onto master 6b6d6df. Each review point:
Verification of 606c168 (local, ports 20200–20219):
These also pass with 606c168:
🤖 Generated with Claude Code |
During a slot migration the migrating node answers -ASK for keys it no longer holds, and the importing node serves such a key only to a command sent right after ASKING. With --retry-on-error the -ASK branch used the MOVED retry path: it resent to the slot-map owner, which is still the migrating node, and without ASKING. The request bounced until --max-retries ran out and ended as an error, or forever with the default unlimited retries. Resend to the primary connection named in the -ASK reply and write ASKING immediately before the resent bytes, so it applies to that command at any --pipeline depth. Its reply is consumed like DISCARD's and is not a workload request. Without a connection to that node the old slot-map routing is kept. --transaction still drops redirects inside a MULTI block: ASKING there would be queued, not applied. Fixes #597 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Over TLS the connection to the importing node can still be in its handshake when the first -ASK arrives. retry_after_ask() only accepted a connected target, so it fell back to the slot map, which sends the request back to the migrating node; with no backoff the retries ran out within the handshake. The TLS cluster CI job failed this way. Accept a target that is still connecting. Its retry queue cannot drain before the connection is up, and the drain timer does not fire again, so fill_pipeline() now drains retries left behind once the connection is connected and set up, as it already does for replays. Keep m_asking set for the life of the request, so a resend after a reconnect is still preceded by ASKING; ASKING changes nothing on a node that is not importing the slot. Log the fallback to slot-map routing, share the retry accounting with retry_after_redirect(), note why the retry ignores --read-preference, and check ASK/sec for the arbitrary command case in the test too. Fixes #597 Co-Authored-By: Claude Opus 5.5 <[email protected]>
retry_after_ask() fell back to the slot map when the connection to the importing node was down and waiting on its reconnect timer. The slot map points at the migrating node, which answers -ASK again, so the request bounced until --max-retries ran out (649-704 errors per run with --max-retries 3 while that node's clients were killed every second), or for millions of retries without a limit. Accept such a connection, as hand_off_replay_requests() does: the retry waits in its queue, and fill_pipeline() sends it once the connection is set up again. Clear m_asking when the request is routed by the slot map again (a MOVED retry or a hand-off), and don't charge ASKING a --rate-limiting token: the resend it prefixes takes its own. The test now kills the importing node's clients during a run, checks with INFO commandstats that ASKING reaches the importing node only, and moves only the even-numbered keys, so the migrating node keeps serving the others. Fixes #597 Co-Authored-By: Claude Opus 5.5 <[email protected]>
After the replay block was rewritten (#613), say directly which retries the fill_pipeline() drain is for. Pass --authenticate when the test cluster has a password, so the reconnect case also runs with AUTH. Co-Authored-By: Claude Opus 5.5 <[email protected]>
606c168 to
2633c6d
Compare
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 2633c6d. Configure here.
| return false; | ||
| if (target == UINT_MAX) { | ||
| benchmark_debug_log("no live primary connection for %s; retrying by slot map\n", status ? status : "-ASK"); | ||
| return retry_after_redirect(conn_id, req); |
There was a problem hiding this comment.
ASK retry misses reconnecting shards
Medium Severity
retry_after_ask only keeps a disconnected importing primary when is_reconnect_pending() is true. For a non-main shard, the reconnect timer clears that flag and then only requests CLUSTER SLOTS on the seed connection, so the importer stays conn_disconnected with no pending reconnect until that refresh dials it. New -ASK redirects in that window fall back to retry_after_redirect, which resends on the slot map without ASKING and can bounce until --max-retries is exhausted.
Reviewed by Cursor Bugbot for commit 2633c6d. Configure here.


Problem
In cluster mode with
--retry-on-error, a request that gets-ASKduring a slot migration never completes (#597). It is resent to the migrating node, withoutASKING, and bounces until--max-retriesruns out and ends as an error. With the default unlimited retries, a--requestsrun never finishes. In a local repro with half the keys of a slot migrated, about 53% of requests on master end as-ASKerrors.Root cause
The
-ASKbranch ofcluster_client::handle_response()used the MOVED retry path,retry_after_redirect():<host>:<port>in the-ASKreply.shard_connection::replay_request()writes only the captured command bytes. Even if a resend reached the importing node, it would arrive withoutASKING, and that node would answer-MOVEDback.Fix
Routing: new
cluster_client::retry_after_ask(). It parses the target from the-ASKreply and finds the primary connection with that address and port. Three connection states are accepted:hand_off_replay_requests()uses.The retry waits in that connection's queue. Only when no such connection exists does it fall back to
retry_after_redirect(), and that fallback is now logged at debug level. The retry goes to a primary whatever--read-preferencesays, because only the importing primary serves the key afterASKING.Retries left over after reconnect:
fill_pipeline()drains retries left in the queue once the connection is connected and set up, the same way it already handles replays. It only does this when no drain timer is pending, so--retry-backoff-msis still respected.Sending ASKING:
replay_request()writes*1\r\n$6\r\nASKING\r\nimmediately before the resent bytes whenever the request'sm_askingflag is set.ASKINGapplies to exactly that command at any--pipelinedepth.replay_request()does not clearm_asking. The flag stays set while the request is routed to the node the-ASKnamed, so a resend after a reconnect is preceded byASKINGagain.retry_after_redirect(), or a hand-off after a topology change.Not counted in stats: the
ASKINGreply is a new internalrt_askingrequest type, handled likert_discard. It is not a workload request, so it is not counted in ops, latency, bytes or routed ops, and its reply is only logged. It does not take a--rate-limitingtoken either, because the resend it prefixes takes its own.Retry accounting:
retry_after_redirect()andretry_after_ask()share it in the newenqueue_redirect_retry().--transactionis unchanged. Redirects inside a MULTI block are dropped on purpose (Cluster --transaction: CLUSTER SLOTS sent inside an open MULTI wedges the main connection #569), and anASKINGsent inside an open MULTI would be queued, not applied. The ASK branch for--transactionnever reaches the retry path.Behaviour change:
ASK/sec. It used to count every bounce of the same request, roughlymax-retries + 1per request on master. It now counts the redirects that actually happen, normally one per ASKed request.Dependency met: with a password-protected cluster and
--reconnect-on-error, requests resent after a reconnect used to go out beforeAUTH(#527). That is fixed by #613, which is now merged, and this branch is rebased onto it. The test passes--authenticatewhen the cluster has a password.test_ask_retry_waits_for_reconnectpasses 2/2 with--oss_password.Test evidence
New
tests/test_cluster_ask_asking.py, which runs on oss-cluster only.Setup:
memtier-1..200.MIGRATEonly the even-numbered keys. The odd ones stay on the migrating node, which still serves them.Memtier runs with
--retry-on-error --max-retries=3 --failed-keys-file.test_ask_retry_sends_askingcovers built-in GET, built-in SET and--command="GET __key__"at--pipeline1 and 16. Each run must:cmdstat_askingcalls > 0 on the importing node and 0 on the other two (all nodes are on 127.0.0.1, so this catches a wrong address match);A
--transactionMULTI/GET/SET/EXEC rotation must send noASKINGat all and produce no-MOVEDfailure.test_ask_retry_waits_for_reconnectkills the importing node's client connections every 0.5 s during a--reconnect-on-error --reconnect-backoff-factor=1 --rate-limiting=500 --pipeline=8 --ratio=1:1run. No request may end on a-ASK/-MOVEDfailure. Replays that run out of retries (connection-dropped) are allowed.Local results (ports 20200–20219):
-ASKfailures per run)-ASKfailures per case)Repro from the review (3 primaries, no password, importing node's clients killed every 1 s,
-n 3000 --pipeline 8 --rate-limiting 500 --ratio 1:1 --reconnect-on-error --reconnect-backoff-factor 1):--max-retries 3-ASKManual repro from #597 (
--max-retries 5, 1000 requests): master ends with 535, 533 and 534 errors (GET, GET+SET, GET at pipeline 16); this branch ends with 0.After rebasing onto master 18f8266 (#613, #615, #618, #599, #612), on one 3-shard cluster,
test_cluster_ask_asking.py,test_cluster_redirect_stats.pyandtest_retry_on_error.pypass 26/26.Before that rebase, these existing tests also passed:
test_cluster_redirect_stats.py,test_retry_on_error.py,test_reconnections.py(23/23);test_cluster_transaction.py,test_transaction_pipeline.py,test_retry_on_error.py,test_reconnections.py(38/38).make format-checkis clean.Fixes #597
Affected versions
2.4.0 through 2.5.2 and master. The ASK retry came with 08cfc24 (#381, first tag 2.4.0). Confirmed by running on master, 2.5.2 and 2.4.0; 2.4.1–2.4.4 and 2.5.0–2.5.1 are derived from history.
🤖 Generated with Claude Code
Note
Medium Risk
Changes cluster redirect/retry behavior on the hot path for migrations and reconnects; incorrect ASK/ASKING pairing could still loop or mis-route, but scope is limited to --retry-on-error and is covered by new integration tests.
Overview
Fixes
--retry-on-errorin cluster mode when keys hit-ASKmid slot migration: retries no longer follow the MOVED path (slot map → migrating node without ASKING), which caused bounce loops or hung runs.-ASKhandling addsretry_after_ask(), which parses the importing node from the reply, queues the resend on that primary (including connecting/reconnect-pending connections), setsrequest::m_asking, and only falls back toretry_after_redirect()if no matching primary exists. MOVED retries clearm_askingso routing is slot-map based again; replay hand-offs do the same.Wire behavior:
replay_request()emitsASKINGimmediately before the captured command whenm_askingis set; internalrt_askingreplies are ignored for workload stats and do not consume--rate-limitingtokens.fill_pipeline()drains retries stuck on a connection that was still handshaking/reconnecting once setup completes.Shared retry enqueue logic moves to
enqueue_redirect_retry(). New oss-cluster tests intest_cluster_ask_asking.pycover GET/SET/arbitrary/transaction and reconnect while the importing node drops clients.Reviewed by Cursor Bugbot for commit 2633c6d. Bugbot is set up for automated code reviews on this repo. Configure here.