Skip to content

Resolve empty ASK and MOVED hosts from the replying connection - #787

Merged
fcostaoliveira merged 2 commits into
masterfrom
codex/fix780-empty-redirect-20261017
Oct 18, 2026
Merged

fcostaoliveira merged 2 commits into
masterfrom
codex/fix780-empty-redirect-20261017

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

An empty host in a cluster ASK or MOVED redirect is valid: it means the endpoint of the connection that received the reply, with the redirected port. memtier instead compares that empty string against known primary addresses, fails to identify the target and retries the stale slot owner. A bounded run can exhaust retries without executing its requests on the target.

Root cause

The shared redirect resolver parses the host literally and has no receiving-connection identity. A refreshed slot map cannot repair ASK during an ongoing migration, and MOVED can arrive before updated topology is available.

Fix

Pass the receiving connection ID to the existing resolver. Substitute its stored endpoint only when the redirect host is empty, preserving the redirected port. Keep explicit hosts, primary-role/readiness checks, retry ownership and ASKING behavior unchanged. Do not substitute the original seed endpoint.

Tests

  • A deterministic two-primary fixture covers ASK/MOVED, GET/SET, explicit/empty hosts, and seed/nonseed reply senders: 16 cases. The nonseed uses a different loopback address, so an incorrect seed-host fallback cannot pass. Seed cases always run; only the nonseed function skips on platforms lacking that alias. Six injected availability controls verify unrelated bind errors still fail. Topology deliberately remains stale.
  • Before: all eight empty-host cases fail target-execution checks; all eight explicit-host controls pass. After: all 16 pass, with exactly 20 original source requests and 20 successful target commands, correct ASKING adjacency/count, JSON Count 20 and no failed-key CSV rows per case.
  • Ordinary build, formatting and all 15 unit programs pass. The final tree includes merged Refresh Git version metadata when rebuilding an existing checkout #778 through a normal fast-forward of its base.
  • These are scripted protocol controls, not a claim of running a real Redis resharding workload. No throughput improvement is claimed.

Affected versions

Directly reproduced on current base cae16bf6a2c1bce7df051b3db45e4f6c89dfccae and the independently tested #777 topology-normalization head. Retry support entered in 08cfc24ac3a056fadbaac7a225ed260aee8f6431, first released in 2.4.0. Releases 2.4.0–2.5.2 have the broader ASK-routing limitation; this range is source/history attribution, not execution of every release. Unreleased ac5dca8d66fc84d27bb675d204641e7e0078a247 fixed explicit-host ASK forwarding but left this empty-host variant. The shared resolver also handles MOVED, now covered by the paired controls. No fixed release exists yet.

Fixes #780

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

🤖 Automated first-pass review — a human maintainer's review is still required before merge.

Thanks, this is small and well scoped. The empty-host substitution only runs when addr_len == 0, so explicit hosts behave exactly as before. conn_id always comes from the replying connection's own retry path, so the m_connections[conn_id] index looks safe. The 16-case matrix, with stale topology and a second loopback for the nonseed sender, is the right way to stop a seed-host fallback from passing by accident. Good to see the JSON Count and failed-keys CSV assertions as well.

One question, not blocking: the match is still an exact string compare against each connection's stored m_address. As far as I can tell, the seed connection keeps whatever was passed to --server, while connections dialed from CLUSTER SLOTS store the address the node reports. If someone runs with --server=localhost (or a DNS name) and the -ASK :port comes back on the seed connection, the substituted host would be localhost but the target would be stored as 127.0.0.1. That would miss, and the request would go back to slot-map routing. It's no worse than before, but did you consider that case, or is it worth a short note in the comment? The tests use literal IPs everywhere, so they wouldn't catch it.

The core fix looks right to me.

@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Thanks. I checked this path and added independent runtime controls. The bootstrap seed does not retain the raw --server string: client::connect() resolves it and stores the numeric address produced by inet_ntop() through set_address_port().

Both the semantics and test reviewers ran --server=localhost --ipv4 with targets advertised as 127.0.0.1, covering empty ASK and MOVED replies for GET and SET. All four combinations pass: 20 source requests, 20 target completions, ASKING only for ASK, Count 20 and no failed-key rows. Thus the seed-host case described here already resolves correctly.

Arbitrary hostname aliases advertised for nonseed connections still use the existing exact-string matching policy; this change does not add DNS alias equivalence. The core fix remains substitution of the actual replying connection's stored endpoint while preserving the redirect port.

@fcostaoliveira
fcostaoliveira merged commit ae04302 into master Oct 18, 2026
132 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty-host ASK redirects retry the source instead of the importing primary

1 participant