Skip to content

Conversation

@barshaul
Copy link

@barshaul barshaul commented Feb 3, 2026

Handle MOVED error pointing to same endpoint

Problem

When Redis/Valkey servers are deployed behind DNS records, load balancers, or proxies (as is common in managed environments), a MOVED error may be returned with a target node endpoint that is the same endpoint from which the error originated. Before the proposed change, when StackExchange.Redis received a MOVED error pointing to the same endpoint, it would fail the request and propagate the MOVED exception back to the application.

Issue ref: #2990

Solution

When a MOVED error points to the same endpoint, the client now triggers a reconnection before retrying the command. This allows the DNS record, proxy, or load balancer to route the new connection to a different underlying server host, enabling the retry to succeed.

Why proactive reconnection is necessary

The server closes the connection on its end immediately after sending the MOVED-to-same-endpoint error. However, due to the multiplexed nature of StackExchange.Redis connections, the library wouldn't notice the disconnection when it retries the request—all Write and Flush operations return successfully even though the underlying connection is broken. The disconnection is only detected when attempting to read the response.

At that point, it isn't safe to retry on the connection failure: we don't know if the request was actually sent to the server, so the connection error is raised back to the application, which also cannot determine if it's safe to retry. By initiating a reconnect immediately following the MOVED-to-same-endpoint error, we ensure the retry occurs on a fresh connection to a new server host.

Changes

Core fix:

  • ResultProcessor.cs: Detect when MOVED endpoint matches the current server endpoint and trigger reconnection by disposing the existing connection.

Tests:

  • MovedToSameEndpointTests.cs: Integration test verifying the reconnect-and-retry behavior
  • MovedTestServer.cs: Test server helper that simulates MOVED responses pointing to the same endpoint

@barshaul barshaul force-pushed the moved_same_endpoint branch from 948a601 to 9c32b44 Compare February 3, 2026 13:35
@barshaul barshaul marked this pull request as ready for review February 3, 2026 13:50
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.

1 participant