Repository navigation
feat: sharded subscriber health check - #2268
Conversation
stop() removes the subscriber instance's listeners, so a pending connect() never settled. A reset waiting on that start hung with isResetting stuck at true, and every later reset was queued behind it forever. Settle the start when the subscriber is stopped so the reset can finish. Co-Authored-By: Claude Opus 5.5 <[email protected]>
On a Redis Enterprise node reboot, the surviving proxy stops answering commands on existing sharded subscriber connections. The connections stay ready and keep delivering smessage, so ClusterSubscriberGroup.reset() keeps them as healthy and the SSUBSCRIBE for inherited slots is never answered. The new shardedSubscriberHealthCheckInterval option arms a timer per subscriber. A quiet subscriber sends PING. If the same command is still at the head of the command queue on two consecutive checks, the subscriber disconnects, which emits -node so the group replaces it. A smessage restarts the timer only while nothing waits for a reply, because a stuck proxy keeps delivering messages. Sharded subscribers now disable autopipelining so PING is written immediately and is visible in the command queue at the next check. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Double the post-failure recovery wait to 90s and the per-test timeout to 360s, so the longer wait fits after a reboot action that can take up to 120s. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…dule The health check only needs an event emitter with a command queue, a status, ping and disconnect. Taking that interface instead of Redis lets a unit test drive it with a fake connection and fake timers, without a Redis server. Behavior is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The health check guards against a Redis Enterprise proxy that stops answering commands on a sharded subscriber connection while it still delivers smessage. Reproducing that needs an RE node reboot, so drive the check with a fake connection and fake timers instead: pings on idle, message-based postponing only while nothing waits, disconnect on a head that stays unanswered across two fires, and nothing after stop. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nect A start that stop() cuts short now settles instead of hanging, so the group's success handler ran for it and cleared the node's failure count. A node whose starts kept getting stopped mid-connect then retried at the first backoff step every time. Clear the failure count only when the subscriber actually reached the connected status. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b5721ff57a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
|
|
|
|
|
The health check peeked at the connection's commandQueue and compared its head across two fires, and it skipped PING while sharded messages arrived unless the queue was empty. That coupled the module to Redis internals and reasoned about liveness indirectly, while a node that is stuck for commands keeps pushing messages anyway. Send one PING per interval and disconnect when it is still unanswered at the next fire. Replies are ordered, so a PING queued behind a stuck SSUBSCRIBE hangs too. The check arms on connect, so a handshake that is not answered within one interval also disconnects, and it stops on close. The PING deadline is extended to the interval, so a shorter commandTimeout cannot reject it early. A server error reply such as NOPERM counts as an answer, while a local rejection does not. Co-Authored-By: Claude Fable 5.2 <[email protected]>
A failed SSUBSCRIBE during resubscribe was only logged, so a slot whose resubscribe got MOVED (or failed on a closing connection) stayed unsubscribed until the topology changed again. When the node that answered MOVED still listed itself as the slot owner, reset() saw no topology change and skipped, leaving the channels silently dropped. Track the slots whose resubscribe failed and schedule a slots refresh with backoff. Only that backoff retry forces reset() to resubscribe with an unchanged topology, so the immediate refresh triggered by the MOVED reply cannot start an unthrottled refresh loop. Non-transient error replies such as NOPERM are surfaced as nodeError instead of being retried. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…bers A resubscribe pending on a subscriber that stop() or reset() has since dropped could still settle later. Its rejection re-armed the retry timer after stop() had cleared it, so the timer fired after the cluster ended, or triggered a slots refresh while the cluster was closing. Replies are now applied only while the subscriber that sent them is still the one held for its node. The health check path is unaffected: it disconnects the subscriber without removing it, so its rejection still schedules a retry. Rename the resubscribeFailed event to resubscribeRetryDue, since it fires when the backoff ends rather than when the failure happens. Drop the enableAutoPipelining: false override on sharded subscribers. It existed so PING would sit at the command queue head, and the health check no longer inspects the queue. Sharded subscribers follow redisOptions.enableAutoPipelining again, as on main. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 867019c93f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
A resubscribe that failed with an error reply a retry cannot fix, such as NOPERM after an ACL change, left the slot's channels unsubscribed and only surfaced as a generic nodeError. Emit it through the cluster's "error" event instead, matching autoResubscribe on a standalone client, so the application learns that the channels are no longer subscribed. Also rename the internal resubscribeRetryDue event to resubscribeRetry. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bd7668604b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit bd76686. Configure here.
A late ssubscribe reply from a subscriber that no longer owns the slot could mark the slot resubscribed and cancel the retry scheduled by the new owner's failure, leaving its channels unsubscribed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each reset that ran while a sharded subscriber was still connecting added another "ready" listener per slot, so the subscriber sent SSUBSCRIBE once per reset when it became ready. Keep a single listener per subscriber and read its slots and channels when it becomes ready. Stop retrying resubscribes that fail with a local error. A closed connection ends the subscriber, and the reset that follows replaces it. A timed-out SSUBSCRIBE still runs on a live node, and a resend to a stuck node would only queue behind the stuck command. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Default shardedSubscriberHealthCheckInterval to 10000 ms so sharded subscribers detect a node that stops answering without extra config. Set the option to null to disable the check. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 022051d804
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 76b4885a6d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Unit tests drive ClusterSubscriberGroup with fake timers: backoff growth, the loop guard against MOVED-triggered refreshes, one timer for several slots, no retry for local errors, and cancellation on stop, sunsubscribeAll and channel removal. MockServer tests cover a MOVED reply from a node that still owns the slot, a bounded number of CLUSTER SLOTS refreshes while resubscribes keep failing, and the health check end to end: replacement on an unanswered PING or handshake, no churn while PING is answered, the null and default intervals, and no PING after stop or disconnect. Co-Authored-By: Claude Opus 5.5 <[email protected]>
76b4885 to
751a590
Compare
…ribers Only a subscriber that was connected requests an immediate slots refresh when it ends; a failed start already schedules one after a backoff. Connect failures that arrive while a retry is pending now join it instead of starting their own retry chains. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d subscriber health check Raise shardedSubscriberHealthCheckInterval values below 1000ms to 1000ms. A shorter interval cannot reliably cover the PING round trip, and event loop pauses would disconnect healthy subscribers. Delay the first PING after ready by a random 50-200ms so subscribers that become ready together do not ping in lockstep. Later PINGs keep the plain interval. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e8bc530692
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| this.healthCheck = healthCheckInterval | ||
| ? new ShardedSubscriberHealthCheck( |
There was a problem hiding this comment.
Apply the minimum interval to a configured value of zero
With shardedSubscribers: true and shardedSubscriberHealthCheckInterval: 0, this truthiness check skips health-check initialization entirely, so the constructor's 1000ms clamp never runs. The new option documentation promises that values below 1000 are raised to 1000, but this configuration instead creates no timer or probes and can leave a blackholed subscriber undetected. Check for null/undefined rather than truthiness so zero receives the documented minimum interval.
Useful? React with 👍 / 👎.
…1000 Validate shardedSubscriberHealthCheckInterval in the Cluster constructor instead of silently raising small values to the 1000ms minimum. Values that are not null or a finite number of at least 1000 now throw. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d09b8fd831
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| } | ||
|
|
||
| this.channels.clear(); | ||
| this.clearResubscribeRetry(); |
There was a problem hiding this comment.
Suspend restore retries while unsubscribing all shards
If a transient restore retry is pending when the application calls zero-argument sunsubscribe(), and an unsubscribe acknowledgement takes longer than the backoff, the retry can run reset() while sunsubscribeAll() is awaiting replies. Because the channels are still tracked, it queues a fresh SSUBSCRIBE after SUNSUBSCRIBE. The method then returns 0 and clears its channel map, but Redis ends up subscribed again, so messages continue and a later zero-argument sunsubscribe() no longer targets that shard. Suspend resubscription retries for the entire unsubscribe operation, rather than cancelling them only after its replies arrive.
Useful? React with 👍 / 👎.
# [6.1.0](v6.0.0...v6.1.0) (2026-11-23) ### Bug Fixes * accept field arrays in hmget/hmgetBuffer types ([#2167](#2167)) ([c0cd66c](c0cd66c)) * align auto-pipeline callbacks for dynamic commands ([#2180](#2180)) ([7479cab](7479cab)) * apply the legacy reply shape to uppercase command names ([#2252](#2252)) ([8ecb423](8ecb423)) * clean up Sentinel failover subscriptions after quit ([#2198](#2198)) ([727edfa](727edfa)) * close the monitor connection when monitor() rejects ([#2247](#2247)) ([3cfe93f](3cfe93f)) * cluster stuck in close ([#2217](#2217)) ([a5fad1d](a5fad1d)) * **cluster:** bucket autopipelined MSET objects by their first key ([#2207](#2207)) ([b4e3237](b4e3237)) * **cluster:** do not reject pipeline commands for connecting nodes when offline queue is disabled ([#2277](#2277)) ([71516ca](71516ca)), closes [#2096](#2096) [Cluster#sendCommand](https://github.com/Cluster/issues/sendCommand) [#2276](#2276) * **cluster:** do not throw when auto-pipelining meets an uncached slot ([#2233](#2233)) ([e04bb49](e04bb49)) * **cluster:** don't fall back to a replica when no primary is left ([#2275](#2275)) ([c353e34](c353e34)) * **cluster:** emit sharded subscriber connect errors silently ([#2241](#2241)) ([00c9a22](00c9a22)) * **cluster:** end when quit() or disconnect() is called while reconnecting ([#2240](#2240)) ([8526785](8526785)) * **cluster:** hash autopipelined Buffer keys by their bytes ([#2208](#2208)) ([a8378bd](a8378bd)), closes [Command#getSlot](https://github.com/Command/issues/getSlot) * **cluster:** hash lone surrogates as the UTF-8 Node sends ([#2242](#2242)) ([cfa464d](cfa464d)) * **cluster:** keep forwarding sharded messages after reconnecting from end ([#2251](#2251)) ([326e987](326e987)) * **cluster:** map every slot when stringNumbers is enabled ([#2255](#2255)) ([8ce4115](8ce4115)) * **cluster:** match Buffer shard channels when unsubscribing ([#2203](#2203)) ([d997d01](d997d01)) * **cluster:** pass the retry delay to the reconnecting event ([#2291](#2291)) ([ed50383](ed50383)) * **cluster:** resend only the redirected command in a pipeline ([#2214](#2214)) ([46b3191](46b3191)), closes [#2075](#2075) [Pipeline#exec](https://github.com/Pipeline/issues/exec) [Cluster#sendCommand](https://github.com/Cluster/issues/sendCommand) [Pipeline#exec](https://github.com/Pipeline/issues/exec) [Cluster#sendCommand](https://github.com/Cluster/issues/sendCommand) [Pipeline#exec](https://github.com/Pipeline/issues/exec) * **cluster:** stay ended when nodes removed by disconnect() end late ([#2237](#2237)) ([61896e5](61896e5)), closes [#2217](#2217) * **cluster:** stop refreshing slots when disconnect() is called during a refresh ([#2249](#2249)) ([80501ed](80501ed)) * **cluster:** support zero-argument sunsubscribe with sharded subscribers ([#2137](#2137)) ([13ff050](13ff050)), closes [#2133](#2133) * **cluster:** vendor cluster-key-slot to fix empty hash tag slot bug ([#2172](#2172)) ([b479b76](b479b76)) * correct Sentinel retry ordering after node connection failures ([#2246](#2246)) ([a10e0fa](a10e0fa)) * decode integer replies up to MAX_SAFE_INTEGER exactly ([#2164](#2164)) ([28940b5](28940b5)) * decode RESP3 attribute replies instead of failing the connection ([#2213](#2213)) ([6a8cb3e](6a8cb3e)), closes [#decodeNestedType](https://github.com/redis/ioredis/issues/decodeNestedType) [#decodeMapAsObject](https://github.com/redis/ioredis/issues/decodeMapAsObject) [#decodeMapKey](https://github.com/redis/ioredis/issues/decodeMapKey) * decode RESP3 doubles with Number ([#2150](#2150)) ([6fb5a10](6fb5a10)) * end when quit() or disconnect() is called while reconnecting ([#2245](#2245)) ([81bc16a](81bc16a)) * handle rejection from the db-restoring select on reconnectOnError ([#2229](#2229)) ([1b744ca](1b744ca)) * handle rejections from auto-resubscribe and select on reconnect ([#2187](#2187)) ([de2fbdf](de2fbdf)) * inherit connectTimeout for cluster subscribers ([#2220](#2220)) ([db57c2d](db57c2d)) * keep String.prototype in fast mode after defining VerbatimString ([#2206](#2206)) ([90e1261](90e1261)) * keep subscriber mode while other channel kinds remain subscribed ([#2196](#2196)) ([eb97beb](eb97beb)) * keep the exec error out of its own previousErrors ([#2218](#2218)) ([2c602cf](2c602cf)) * keep the selected db for commands queued while reconnecting ([#2235](#2235)) ([9f90154](9f90154)) * preserve empty keys and match patterns in scan streams ([#2199](#2199)) ([b169c3a](b169c3a)) * redact credentials from the command attached to errors ([#2231](#2231)) ([a26f8de](a26f8de)), closes [#1713](#1713) * reject unfulfilled commands dropped on reconnect ([#2194](#2194)) ([d95d05a](d95d05a)), closes [#2193](#2193) * reset retry attempts when connect() is called after giving up ([#2204](#2204)) ([b597303](b597303)), closes [#1463](#1463) * reset the manual close state when connect() is called after end ([#2250](#2250)) ([7713c4b](7713c4b)) * resolve argument-less (p)unsubscribe once its own kind is empty ([#2238](#2238)) ([280812b](280812b)) * restore the db selected by a non-lowercase SELECT after reconnecting ([#2248](#2248)) ([400b774](400b774)) * **sentinel:** handle errors on failover detector connections ([#2257](#2257)) ([09bcda5](09bcda5)) * **sentinel:** retry unreachable sentinels in a loop instead of recursing ([#2270](#2270)) ([6bee8d2](6bee8d2)) * **types:** accept documented TLS profile options ([#2195](#2195)) ([56a7fb8](56a7fb8)), closes [#1626](#1626) * **types:** add event overloads to Cluster interface ([#2201](#2201)) ([3996eaf](3996eaf)), closes [#2191](#2191) * **types:** add smessage and smessageBuffer event overloads ([#2191](#2191)) ([ee48f4c](ee48f4c)), closes [#2190](#2190) * **types:** allow number for zrange stop argument ([#2163](#2163)) ([932f4c2](932f4c2)) ### Features * add BITRANGEINTARRAY command ([#2279](#2279)) ([b141399](b141399)) * add set member expiration commands ([#2261](#2261)) ([5efba6b](5efba6b)), closes [redis/redis#15938](redis/redis#15938) * bless commands ([#2209](#2209)) ([9181ee0](9181ee0)) * **cluster:** allow configuring node role for Pub/Sub subscriber ([#2176](#2176)) ([6b9130c](6b9130c)) * sharded subscriber health check ([#2268](#2268)) ([1b25ffb](1b25ffb)) * smart client handoffs ([#2165](#2165)) ([d8ae3cb](d8ae3cb)) * sorted set move commands ([#2288](#2288)) ([2f4f09d](2f4f09d))
|
🎉 This PR is included in version 6.1.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |

This pull request adds
shardedSubscriberHealthCheckInterval, an opt-in health check for sharded subscriber connections. When the option is set, a subscriber that gets no sharded message for one interval sendsPING. If the same command is still unanswered at the next check, the subscriber disconnects and the cluster replaces it. A busy subscriber never sendsPING. The option is unset by default, and then the check adds no timer, no listener and noPING. Sharded subscriber connections now always disable autopipelining, even whenredisOptionsturns it on.A subscriber connection can stop answering commands while it still delivers messages, for example behind a proxy after a node failure. The connection still reports ready, so a new
SSUBSCRIBEon it never gets a reply, and those channels go silent. This change detects such connections and replaces them.It also fixes two subscriber group bugs found during testing. A
start()thatstop()interrupts now settles, soreset()no longer hangs. Such a start also no longer resets the node's retry backoff.Note
Medium Risk
Changes cluster sharded pub/sub connection lifecycle, automatic disconnects, and resubscribe timing—important for message delivery during failovers, though behavior is configurable and well-tested.
Overview
Adds
shardedSubscriberHealthCheckInterval(default10000, minimum1000, ornullto disable) so each sharded pub/sub connection is probed with periodicPING; unanswered handshakes or pings trigger disconnect and cluster replacement via-node/subscriberLost, documented in README andClusterOptions.Introduces
ShardedSubscriberHealthCheckand wires it throughShardedSubscriber, including jitter on the first ping and PING timeout extension past shortcommandTimeout.ShardedSubscriber.start()now racesconnect()againststop()soreset()does not hang, and only truly connected subscribers clear connect-failure backoff;subscriberLosttriggers an immediate slots refresh instead of every-node.ClusterSubscriberGroupgains backoff retries for transientSSUBSCRIBEfailures (MOVED, etc.) without floodingCLUSTER SLOTS, emitsresubscribeErrorfor permanent Redis errors, and refactors resubscribe with a single per-subscriberreadylistener. The cluster client validates the new option and coalesces connect-failure refresh timers. Functional, unit, and scenario tests cover health checks, resubscribe behavior, and longer failure-recovery timeouts.Reviewed by Cursor Bugbot for commit d09b8fd. Bugbot is set up for automated code reviews on this repo. Configure here.