Skip to content

fix(cluster): recreate stale connection on circular MOVED - #2135

Merged
PavelPashov merged 1 commit into
redis:mainfrom
PavelPashov:fix/1865-recreate-stale-moved-connection
Jul 16, 2026
Merged

PavelPashov merged 1 commit into
redis:mainfrom
PavelPashov:fix/1865-recreate-stale-moved-connection

Conversation

@PavelPashov

@PavelPashov PavelPashov commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

When a MOVED redirect points back to the same pooled node, replace the existing connection before retrying so proxy-backed endpoints can recover after their backing server changes.

Fixes #1865


Note

Medium Risk
Touches core cluster redirect and connection-pool lifecycle; behavior change is narrow (self-referential MOVED only) but mistakes could affect node events or pool consistency.

Overview
Fixes infinite retry loops when a MOVED redirect targets the same address as the connection that returned the error (e.g. a proxy whose backend changed while the pooled TCP connection stayed open).

ConnectionPool gains recreate(), which drops the stale client from the pool, disconnects it, and opens a new one. The stale connection’s end handler no longer removes the replacement, and -node is emitted only after the new connection is registered.

Cluster command routing records lastRedis per attempt; on MOVED, if the mapped target is the same node key and still the pooled instance that failed, it calls recreate() instead of findOrCreate() so concurrent circular MOVEDs share a single refresh. Normal MOVED to another host is unchanged.

Functional and unit tests cover the proxy-style scenario and single recreate under concurrency.

Reviewed by Cursor Bugbot for commit 5153baa. Bugbot is set up for automated code reviews on this repo. Configure here.

When a MOVED redirect points back to the same pooled node, replace the
existing connection before retrying so proxy-backed endpoints can recover
after their backing server changes.

Fixes redis#1865.
@PavelPashov
PavelPashov requested a review from nkaradzhov July 3, 2026 13:44
@PavelPashov

Copy link
Copy Markdown
Contributor Author

run sharded pub sub tests

@uglide

uglide commented Jul 3, 2026

Copy link
Copy Markdown
Contributor
Testcase Errors Failures Skipped Total
Root Suite 0 0 0 0
Sharded Pub/Sub E2E - Basic 0 0 0 4
Sharded Pub/Sub E2E - Connection Lifecycle 0 0 0 3
Sharded Pub/Sub E2E - Failure Recovery Multiple Subscribers 0 0 0 4
Sharded Pub/Sub E2E - Failure Recovery Single Subscriber 0 0 0 4

---- Details for maintainers

@uglide

uglide commented Jul 3, 2026

Copy link
Copy Markdown
Contributor
Testcase Errors Failures Skipped Total
Root Suite 0 0 0 0
Sharded Pub/Sub E2E - Basic 0 0 0 4
Sharded Pub/Sub E2E - Connection Lifecycle 0 0 0 3
Sharded Pub/Sub E2E - Failure Recovery Multiple Subscribers 0 0 0 4
Sharded Pub/Sub E2E - Failure Recovery Single Subscriber 0 1 0 4

---- Details for maintainers

1 similar comment
@uglide

uglide commented Jul 3, 2026

Copy link
Copy Markdown
Contributor
Testcase Errors Failures Skipped Total
Root Suite 0 0 0 0
Sharded Pub/Sub E2E - Basic 0 0 0 4
Sharded Pub/Sub E2E - Connection Lifecycle 0 0 0 3
Sharded Pub/Sub E2E - Failure Recovery Multiple Subscribers 0 0 0 4
Sharded Pub/Sub E2E - Failure Recovery Single Subscriber 0 1 0 4

---- Details for maintainers

@PavelPashov
PavelPashov merged commit 08c8967 into redis:main Jul 16, 2026
19 checks passed
@PavelPashov
PavelPashov deleted the fix/1865-recreate-stale-moved-connection branch July 16, 2026 11:15
github-actions Bot pushed a commit that referenced this pull request Jul 29, 2026
# [6.0.0-beta.1](v5.11.1...v6.0.0-beta.1) (2026-07-29)

* Add RESP3 ([#2127](#2127)) ([5d0862e](5d0862e))

### Bug Fixes

* clear stale socket timeout on reconnect ([#2148](#2148)) ([6455dbe](6455dbe))
* **cluster:** recreate stale connection on circular MOVED ([#2135](#2135)) ([08c8967](08c8967))
* **cluster:** validate MOVED slot to prevent Array.prototype pollution ([#2151](#2151)) ([9618206](9618206)), closes [#1267](#1267)
* **command:** serialize large integer arguments in decimal notation ([#2136](#2136)) ([09b8d04](09b8d04))
* **redis:** keep reconnecting when connection closes during client setup ([#2099](#2099)) ([#2123](#2123)) ([f9a66bc](f9a66bc))
* **sentinel:** preserve zero preferred slave priority ([#2129](#2129)) ([a3f9f2d](a3f9f2d))
* **tracing:** redact values for GETSET and PSETEX ([#2134](#2134)) ([832765d](832765d))

### Features

* add LMOVEM and BLMOVEM command support ([#2144](#2144)) ([c26af46](c26af46))
* add Redis 8.10 set cardinality commands ([#2143](#2143)) ([301099b](301099b))
* support MAXCOUNT and MAXSIZE for stream reads ([#2142](#2142)) ([ae5e41b](ae5e41b))

### BREAKING CHANGES

* ioredis now requires Node.js 20 or newer and uses RESP3 by default. Set `protocol: 2` to retain the v5 wire protocol.
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 6.0.0-beta.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

github-actions Bot pushed a commit that referenced this pull request Jul 31, 2026
# [6.0.0](v5.11.1...v6.0.0) (2026-07-31)

* Add RESP3 ([#2127](#2127)) ([5d0862e](5d0862e))

### Bug Fixes

* clear stale socket timeout on reconnect ([#2148](#2148)) ([6455dbe](6455dbe))
* **cluster:** recreate stale connection on circular MOVED ([#2135](#2135)) ([08c8967](08c8967))
* **cluster:** validate MOVED slot to prevent Array.prototype pollution ([#2151](#2151)) ([9618206](9618206)), closes [#1267](#1267)
* **command:** serialize large integer arguments in decimal notation ([#2136](#2136)) ([09b8d04](09b8d04))
* **redis:** keep reconnecting when connection closes during client setup ([#2099](#2099)) ([#2123](#2123)) ([f9a66bc](f9a66bc))
* **sentinel:** preserve zero preferred slave priority ([#2129](#2129)) ([a3f9f2d](a3f9f2d))
* **tracing:** redact values for GETSET and PSETEX ([#2134](#2134)) ([832765d](832765d))
* **types:** export ScanStreamOptions, RedisStatus and ClusterStatus ([#2158](#2158)) ([cf3bf71](cf3bf71))

### Features

* add LMOVEM and BLMOVEM command support ([#2144](#2144)) ([c26af46](c26af46))
* add Redis 8.10 set cardinality commands ([#2143](#2143)) ([301099b](301099b))
* himport managed fieldsets ([#2159](#2159)) ([729f174](729f174))
* improve default connection resilience ([#2160](#2160)) ([6d0716e](6d0716e))
* support MAXCOUNT and MAXSIZE for stream reads ([#2142](#2142)) ([ae5e41b](ae5e41b))

### BREAKING CHANGES

* ioredis now requires Node.js 20 or newer and uses RESP3 by default. Set `protocol: 2` to retain the v5 wire protocol.
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 6.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ERR MOVED with ioredis 5.3.1 when connected to ElastiCache Serverless

3 participants