Node.js based forum software built for the modern web
fix: don't publish before pubClient is connected
Barış Soner Uşaklıcdf5d18f547f
diff --git a/src/database/redis/pubsub.js b/src/database/redis/pubsub.jsindex b61b266d67..a7d220682d 100644--- a/src/database/redis/pubsub.js+++ b/src/database/redis/pubsub.js@@ -10,7 +10,7 @@ let channelName;const PubSub = function () {const self = this;channelName = `db:${nconf.get('redis:database')}:pubsub_channel`;-+ self.queue = [];connection.connect().then((client) => {self.subClient = client;self.subClient.subscribe(channelName);@@ -30,13 +30,20 @@ const PubSub = function () {connection.connect().then((client) => {self.pubClient = client;+ self.queue.forEach(payload => client.publish(channelName, payload));+ self.queue.length = 0;});};util.inherits(PubSub, EventEmitter);PubSub.prototype.publish = function (event, data) {- this.pubClient.publish(channelName, JSON.stringify({ event: event, data: data }));+ const payload = JSON.stringify({ event: event, data: data });+ if (this.pubClient) {+ this.pubClient.publish(channelName, payload);+ } else {+ this.queue.push(payload);+ }};module.exports = new PubSub();