Skip to content

Fix/empty hostname cluster slots#5373

Merged
avifenesh merged 1 commit intovalkey-io:mainfrom
PhiloInc:fix/empty-hostname-cluster-slots
Feb 14, 2026
Merged

Fix/empty hostname cluster slots#5373
avifenesh merged 1 commit intovalkey-io:mainfrom
PhiloInc:fix/empty-hostname-cluster-slots

Conversation

@NeoPhi
Copy link
Contributor

@NeoPhi NeoPhi commented Feb 14, 2026

Summary

AWS ElastiCache (plaintext, cluster mode, Redis 7.2.4) returns hostname: "" (empty string) in the CLUSTER SLOTS metadata for every node. The parser was wrapping this in Some(""), which caused unwrap_or_else at line 252 to use the empty string instead of falling back to the IP address from the primary identifier.

This resulted in connection addresses like :6379 (no host), which fail immediately. Because refresh_slots_inner() silently drops connection errors, createClient resolves successfully but the client has zero usable connections. Every subsequent command fails with AllConnectionsUnavailable.

Issue link

This Pull Request is linked to issue (URL): #5367

Features / Behaviour Changes

The fix filters out empty hostname strings at parse time, so they are treated the same as absent hostnames, and the IP from the primary identifier is used instead.

Implementation

Checks for a non-empty hostname.

Limitations

Testing

Unit test added.

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one issue.
  • Commit message has a detailed description of what changed and why.
  • Tests are added or updated.
  • CHANGELOG.md and documentation files are updated.
  • Linters have been run (make *-lint targets) and Prettier has been run (make prettier-fix).
  • Destination branch is correct - main or release
  • Create merge commit if merging release branch into main, squash otherwise.

@avifenesh
Copy link
Member

@NeoPhi please sign off on the commit to make DCO happy.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a cluster-topology parsing edge case in the shared Rust core (glide-core) where AWS ElastiCache returns hostname: "" in CLUSTER SLOTS metadata, which previously produced invalid connection addresses (e.g., :6379) and could lead to AllConnectionsUnavailable.

Changes:

  • Treat empty-string hostname values in CLUSTER SLOTS metadata as absent during parsing (so IP-based fallback works).
  • Add a unit test covering the empty-hostname metadata case (for both metadata formats).
  • Document the fix in CHANGELOG.md.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
glide-core/redis-rs/redis/src/cluster_topology.rs Filters out empty hostname metadata and adds a unit test to ensure fallback to IP-based addresses.
CHANGELOG.md Adds a CORE “Fixes” entry describing the ElastiCache empty-hostname issue and resolution.

Comment on lines 203 to 205
let h = String::from_utf8_lossy(value_bytes).into_owned();
if !h.is_empty() {
metadata_hostname = Some(h);
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

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

String::from_utf8_lossy(value_bytes).into_owned() allocates even when the hostname is empty. You can avoid the allocation by keeping the Cow<str> and only calling into_owned() after the non-empty check (e.g., check is_empty() on the Cow first).

Suggested change
let h = String::from_utf8_lossy(value_bytes).into_owned();
if !h.is_empty() {
metadata_hostname = Some(h);
let h_cow = String::from_utf8_lossy(value_bytes);
if !h_cow.is_empty() {
metadata_hostname = Some(h_cow.into_owned());

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

Fair comment

@avifenesh
Copy link
Member

@NeoPhi Other than the DCO and copilot small efficiency comment, LGTM.
Please update and ill merge.
Thanks!

@NeoPhi NeoPhi force-pushed the fix/empty-hostname-cluster-slots branch from 6e7ebb2 to c05bbc1 Compare February 14, 2026 13:51
@avifenesh
Copy link
Member

@NeoPhi DCO still failing

AWS ElastiCache (plaintext, cluster mode, Redis 7.2.4) returns
`hostname: ""` (empty string) in the CLUSTER SLOTS metadata for
every node. The parser was wrapping this in `Some("")`, which
caused `unwrap_or_else` at line 252 to use the empty string
instead of falling back to the IP address from the primary
identifier.

This resulted in connection addresses like `:6379` (no host),
which fail immediately. Because `refresh_slots_inner()` silently
drops connection errors, `createClient` resolves successfully but
the client has zero usable connections. Every subsequent command
fails with `AllConnectionsUnavailable`.

The fix filters out empty hostname strings at parse time, so they
are treated the same as absent hostnames, and the IP from the
primary identifier is used instead.

Signed-off-by: Daniel Rinehart <danielr@philo.com>
@NeoPhi NeoPhi force-pushed the fix/empty-hostname-cluster-slots branch from c05bbc1 to 0e909af Compare February 14, 2026 16:08
@NeoPhi
Copy link
Contributor Author

NeoPhi commented Feb 14, 2026

Sorry about that. Think I got it this time.

@avifenesh avifenesh merged commit b750df0 into valkey-io:main Feb 14, 2026
71 of 72 checks passed
@avifenesh
Copy link
Member

@NeoPhi merged, thanks!

prashanna-frsh pushed a commit to prashanna-frsh/valkey-glide that referenced this pull request Feb 16, 2026
Fix: treat empty hostname in CLUSTER SLOTS metadata as absent

AWS ElastiCache (plaintext, cluster mode, Redis 7.2.4) returns
`hostname: ""` (empty string) in the CLUSTER SLOTS metadata for
every node. The parser was wrapping this in `Some("")`, which
caused `unwrap_or_else` at line 252 to use the empty string
instead of falling back to the IP address from the primary
identifier.

This resulted in connection addresses like `:6379` (no host),
which fail immediately. Because `refresh_slots_inner()` silently
drops connection errors, `createClient` resolves successfully but
the client has zero usable connections. Every subsequent command
fails with `AllConnectionsUnavailable`.

The fix filters out empty hostname strings at parse time, so they
are treated the same as absent hostnames, and the IP from the
primary identifier is used instead.

Signed-off-by: Daniel Rinehart <danielr@philo.com>
Signed-off-by: prashanna-frsh <prashanna.rajendran@freshworks.com>
prashanna-frsh pushed a commit to prashanna-frsh/valkey-glide that referenced this pull request Feb 16, 2026
Fix: treat empty hostname in CLUSTER SLOTS metadata as absent

AWS ElastiCache (plaintext, cluster mode, Redis 7.2.4) returns
`hostname: ""` (empty string) in the CLUSTER SLOTS metadata for
every node. The parser was wrapping this in `Some("")`, which
caused `unwrap_or_else` at line 252 to use the empty string
instead of falling back to the IP address from the primary
identifier.

This resulted in connection addresses like `:6379` (no host),
which fail immediately. Because `refresh_slots_inner()` silently
drops connection errors, `createClient` resolves successfully but
the client has zero usable connections. Every subsequent command
fails with `AllConnectionsUnavailable`.

The fix filters out empty hostname strings at parse time, so they
are treated the same as absent hostnames, and the IP from the
primary identifier is used instead.

Signed-off-by: Daniel Rinehart <danielr@philo.com>
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.

2 participants