Repository navigation
Description
Bug Report
Current Behavior
Lettuce can repeatedly reuse a stale physical cluster connection when AWS ElastiCache replaces nodes while retaining the same node DNS names.
During a node-type change, ElastiCache can temporarily advertise two different node IDs for the same hostname and port: an old node and its replacement. DNS for that hostname changes to the replacement IP, but an existing Lettuce connection can remain connected to the old IP.
When the role moves to the replacement node:
- The old node returns
MOVEDwith the same stable hostname. - Lettuce retries using that hostname and port.
- The existing cached connection for that endpoint is reused without a new DNS resolution.
- The retry reaches the old node and receives
MOVEDagain. - Adaptive and periodic topology refreshes run and discover the new node IDs, but do not replace the stale physical connection.
This is consistently reproduced only on the second consecutive resize without restarting the client:
- Resize 1: 28,204 internally handled
MOVED; zero surfaced failures. - Resize 2: 7,697,720 additional internally handled
MOVEDand 1,539,725 surfacedMOVEDfailures. - Failure window: approximately 6 minutes 25 seconds, about 4,000 surfaced failures per second.
- All ten workers were affected while the shared cluster connection remained open.
- No data mismatches occurred.
Tested and reproduced in Lettuce 6.3.2.RELEASE. The client recovers only after the old sockets disconnect and normal reconnect resolves the stable hostnames to the replacement IPs.
Example masked topology during replacement:
id=<old-node-id> uri=redis://cache-node-0003-002.<cluster-domain>:6379 flags=[SLAVE, REPLICA]
id=<new-node-id> uri=redis://cache-node-0003-002.<cluster-domain>:6379 flags=[MASTER]
Example connection transition when recovery finally occurs:
DisconnectedEvent [... -> cache-node-0003-002.<cluster-domain>/10.x.x.211:6379]
ConnectedEvent [... -> cache-node-0003-002.<cluster-domain>/10.x.x.221:6379]
Stack trace
io.lettuce.core.RedisCommandExecutionException:
MOVED 12646 cache-node-0003-002.<cluster-domain>:6379
at io.lettuce.core.internal.ExceptionFactory.createExecutionException(ExceptionFactory.java:151)
at io.lettuce.core.internal.Exceptions.bubble(Exceptions.java:57)
at io.lettuce.core.internal.Futures.awaitOrCancel(Futures.java:237)
at io.lettuce.core.cluster.ClusterFutureSyncInvocationHandler.handleInvocation(ClusterFutureSyncInvocationHandler.java:135)
at io.lettuce.core.internal.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:86)
at jdk.proxy2/jdk.proxy2.$Proxy26.set(Unknown Source)
at example.RedirectInvestigator$Worker.loadLoop(RedirectInvestigator.java:250)
at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: io.lettuce.core.RedisCommandExecutionException:
MOVED 12646 cache-node-0003-002.<cluster-domain>:6379
at io.lettuce.core.internal.ExceptionFactory.createExecutionException(ExceptionFactory.java:151)
at io.lettuce.core.internal.ExceptionFactory.createExecutionException(ExceptionFactory.java:120)
at io.lettuce.core.protocol.AsyncCommand.completeResult(AsyncCommand.java:124)
at io.lettuce.core.protocol.AsyncCommand.complete(AsyncCommand.java:115)Input Code
Input Code
Security.setProperty("networkaddress.cache.ttl", "5");
Duration timeout = Duration.ofSeconds(5);
RedisURI seed = RedisURI.builder()
.withHost("<configuration-endpoint>")
.withPort(6379)
.withSsl(true)
.withTimeout(timeout)
.build();
ClientResources resources = ClientResources.builder()
.socketAddressResolver(SocketAddressResolver.create(
new DirContextDnsResolver()))
.build();
RedisClusterClient client = RedisClusterClient.create(resources, List.of(seed));
ClusterTopologyRefreshOptions refreshOptions =
ClusterTopologyRefreshOptions.builder()
.enableAllAdaptiveRefreshTriggers()
.enablePeriodicRefresh(Duration.ofSeconds(30))
.dynamicRefreshSources(true)
.closeStaleConnections(true)
.build();
ClusterClientOptions options = ClusterClientOptions.builder()
.topologyRefreshOptions(refreshOptions)
.socketOptions(SocketOptions.builder()
.connectTimeout(timeout.dividedBy(2))
.keepAlive(true)
.build())
.autoReconnect(true)
.validateClusterNodeMembership(false)
.build();
client.setOptions(options);
// One thread-safe connection is shared by all ten workers.
StatefulRedisClusterConnection<String, String> connection = client.connect();
RedisAdvancedClusterCommands<String, String> commands = connection.sync();
// Each worker performs 1,000 idempotent SET/GET cycles per second.
commands.set(key, value);
String actual = commands.get(key);Reproduction procedure:
- Start the client against a TLS-enabled, three-shard cluster with one replica per shard.
- Keep the same client process and shared connection running throughout the test.
- Change the node type from size A to size B and wait until the cluster is available.
- Without restarting the client, change the node type from size B back to size A.
- Observe repeated surfaced
MOVEDfailures during the second replacement.
Expected behavior/code
After topology identifies a replacement node—or after a command receives repeated MOVED responses for the same target—Lettuce should verify that the cached connection still represents the expected node generation.
A stable hostname and port should not by themselves establish that an existing physical connection is valid when the node ID, role, resolved address, or channel generation has changed.
The client should establish a connection to the replacement node without waiting for AWS to close the old socket. Concurrent commands should not be failed unnecessarily, and delayed callbacks from an old channel must not disconnect a newer channel.
Environment
- Lettuce versions:
6.3.2.RELEASE, official7.7.0.RELEASE - Runtime: Java 17
- Service: AWS ElastiCache cluster mode enabled, TLS
- Engine: Valkey/Redis 7 compatible
- Topology: three shards, one replica per shard
- Routing: default upstream/write routing
- One shared
StatefulRedisClusterConnectionacross ten worker threads autoReconnect=true- All adaptive refresh triggers enabled
- Periodic topology refresh every 30 seconds
dynamicRefreshSources=true- Java DNS cache TTL: 5 seconds
Possible Solution
Cached cluster connections should carry identity beyond hostname and port, including the expected node ID, routing role/intent, resolved remote address, and physical channel generation.
When a repeated MOVED indicates that a connection still reaches an old node, Lettuce could:
- Atomically stop routing new commands to the expected stale generation.
- Resolve the hostname again and establish a replacement generation.
- Ensure a delayed callback can retire only the physical generation that dispatched the redirected command.
- Allow already-sent commands on the old channel to drain, with a bounded retirement timeout.
- Route redirected commands through the replacement connection.
A forced disconnect and auto-reconnect prototype eliminated surfaced MOVED failures in this workload, but it can replay commands whose server-side outcome is unknown. Therefore, blindly reconnecting and resending is not generally safe for non-idempotent commands. A production fix should explicitly preserve or document the resulting delivery semantics.
Additional context
The first resize succeeding is not evidence that the issue is fixed. At startup, write connections existed for the original master endpoint names. The first resize promoted the alternate endpoint names, causing cache misses and fresh DNS resolution. The second resize promoted the original names again, at which point cached connections for those stable names still targeted the previous physical nodes.
MOVED_REDIRECT adaptive refresh events occurred throughout the failure window, and topology updates contained the new node IDs. This indicates that adaptive refresh was triggered correctly; refreshed metadata still led to reuse of the stale host/port connection.
The redirect counters stopped increasing immediately after the final old channel disconnected and reconnected to the replacement address.
The test used only idempotent SET/GET operations.
Activity
atakavci commentedon Sep 8, 2026
hi @zj851224,
thank you for reporting the issue in detail and comments around possible solution.
i had a quick look on this and validated that a cluster connection does not get invalidated when same host:port remains in place.
we will need time to analyze and verify potential identifiers of such change and path to switch/replace the underlying connection.
zj851224 commentedon Sep 9, 2026
thanks @atakavci . could you please fix it in both lettuce v6 and v7. we can not use v7 now because it depends on netty 4.2 which conflicts with several other java dependencies in the project still depending on netty 4.1.