Skip to content

Commit f161367

Browse files
authored
fix(ssubscribe): re-subscribe sharded pubsub channels individually (#2021)
1 parent 561f354 commit f161367

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

lib/cluster/ClusterSubscriber.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,28 @@ export default class ClusterSubscriber {
192192
let pending = 0;
193193
for (const type of ["subscribe", "psubscribe", "ssubscribe"]) {
194194
const channels = previousChannels[type];
195-
if (channels.length) {
195+
if (channels.length == 0) {
196+
continue;
197+
}
198+
199+
debug("%s %d channels", type, channels.length);
200+
201+
if (type === "ssubscribe") {
202+
for (const channel of channels) {
203+
pending += 1;
204+
this.subscriber[type](channel)
205+
.then(() => {
206+
if (!--pending) {
207+
this.lastActiveSubscriber = this.subscriber;
208+
}
209+
})
210+
.catch(() => {
211+
// TODO: should probably disconnect the subscriber and try again.
212+
debug("failed to ssubscribe to channel: %s", channel);
213+
});
214+
}
215+
} else {
196216
pending += 1;
197-
debug("%s %d channels", type, channels.length);
198217
this.subscriber[type](channels)
199218
.then(() => {
200219
if (!--pending) {

0 commit comments

Comments
 (0)