Repository navigation
fix(cluster): keep forwarding sharded messages after reconnecting from end - #2251
PavelPashov merged 2 commits into
Conversation
…m end Going to "end" removes every subscriber group listener, and connect() from "end" reused the stripped emitter, so sharded messages and subscriber events were no longer emitted on the Cluster. Attach the listeners again when connect() starts from "end".
Codex Review SummaryThis 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. |
|
@maxymlyskov Thank you for the PR, I'll review it and get back to you |
ioredis scenario sharded pub/sub tests (RE 8.0.22)
Github Test Reporter by CTRF 💚 |
ioredis scenario sharded pub/sub tests (RE 100.0.20)
Github Test Reporter by CTRF 💚 |
ioredis scenario sharded pub/sub tests (RE 8.0.16)
Github Test Reporter by CTRF 💚 |
| if (this.options.shardedSubscribers) { | ||
| this.addSubscriberGroupListeners(); | ||
| } |
There was a problem hiding this comment.
Could we clear the emitter right before re-adding the listeners, so this stays safe even if a future path reaches end without the strip in handleCloseEvent()? Otherwise each connect() from end would add another set of forwarders, which would deliver every smessage twice and trigger two slot refreshes on every moved.
| if (this.options.shardedSubscribers) { | |
| this.addSubscriberGroupListeners(); | |
| } | |
| if (this.options.shardedSubscribers) { | |
| this.subscriberGroupEmitter.removeAllListeners(); | |
| this.addSubscriberGroupListeners(); | |
| } |
There was a problem hiding this comment.
Done in e003d1c. connect() from end now calls removeAllListeners() on the emitter before addSubscriberGroupListeners(), as you suggested. spub_ssub.ts still gives 23 passing, 1 pending, and npm run test:js the same 2947 passing with the 4 failures main has here.
PavelPashov asked for this in review: if a future path reaches `end` without the strip in `handleCloseEvent()`, each `connect()` from `end` would add another set of forwarders, delivering every `smessage` twice and refreshing the slots twice on every `moved`.
Coverage Report for CI Build 44356598762Warning Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes. Warning No base build found for commit Coverage: 92.626%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsRequires a base build to compare against. How to fix this → Coverage Stats💛 - Coveralls |
# [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 📦🚀 |
On a sharded-subscribers
Cluster, if youdisconnect()and thenconnect()again,ssubscribe()still succeeds and the server counts the subscriber, butsmessagenever fires. Classicsubscribe()on the same client works fine after the same reconnect.Cause:
handleCloseEvent()callssubscriberGroupEmitter?.removeAllListeners()right beforesetStatus("end"). The listeners that forward the group's events to the Cluster (smessage,smessageBuffer,-node,moved,subscriberConnectFailed,-subscriber,+subscriber,nodeError,subscribersReady) are only attached once, fromcreateShardedSubscriberGroup(), which the constructor calls.connect()fromendis supported (#2204 resetsretryAttemptsthere) and reuses the stripped emitter. The new ShardedSubscribers still emit into it, so nothing reaches the Cluster: nosmessage, and amovedor-nodefrom a sharded subscriber no longer refreshes the slots either.Fix: the listener wiring moves, unchanged, out of
createShardedSubscriberGroup()intoaddSubscriberGroupListeners().connect()calls it again when it starts fromendwithshardedSubscriberson, next to theretryAttemptsreset. The strip onendstays and the group isn't rebuilt.Nothing gets attached twice.
endis only set right after the strip, a self-reconnect goes throughreconnecting(so neither the strip nor the new branch runs), and a secondconnect()while connecting is rejected by the existing guard.It's 8 lines in one file with a test that shows it, so I'm sending it without an issue under the small bug fix exception in
.github/CONTRIBUTING.md.Against a real 6-node cluster (redislabs/client-libs-test, Redis 8.6, ports 3000-3005, Node v22.23.3). Round 1 is a fresh client, round 2 is after
disconnect()+connect(). Same result in 3 runs each:Tests:
New case in
test/functional/cluster/spub_ssub.ts, next to the "should receive messages - RESP" tests: "should receive messages after connect() is called following end". It ssubscribes, waits forend, callsconnect(), ssubscribes again and expects the pushedsmessage. Withmain'slib/cluster/index.ts:On the branch it passes, and
spub_ssub.tsas a whole gives 23 passing, 1 pending.npm run test:js: 2947 passing, 25 pending, 4 failing: autoPipelining single node and cluster "should handle large pipelines without RangeError", maintenance handoff "returns to the configured endpoint after endpointless MOVING", connection connectTimeout "should ignore timeout if connect". The same 4 fail onmainon this machinenpm run test:clusteron the docker cluster: same failure onmainand the branch (ClusterSubscriberGroup "receive messages on the channel after the slot was moved", from the test cluster's slot state)npm run buildpasses,prettier --checkclean,eslintclean on both filesNote
Low Risk
Narrow change to sharded subscriber event wiring on manual reconnect from end; no auth or data-path changes, with a targeted regression test.
Overview
Fixes sharded pub/sub (
smessage) silently breaking after a manualdisconnect()→connect()when the cluster reachesend: closing still stripssubscriberGroupEmitterlisteners, but reconnect fromendnow re-attaches them.Listener setup is refactored into
addSubscriberGroupListeners(), called fromcreateShardedSubscriberGroup()and again inconnect()whenstatus === "end"andshardedSubscribersis enabled—restoring forwarding forsmessage, slot refreshes onmoved/-node, and related sharded subscriber events.Adds a functional test that
ssubscribe+smessagework afterdisconnect,end, andconnect().Reviewed by Cursor Bugbot for commit e003d1c. Bugbot is set up for automated code reviews on this repo. Configure here.