From 5046088bf7f414acaa3bfd71769dfe96ade347c9 Mon Sep 17 00:00:00 2001 From: SirStendec Date: Sun, 5 Nov 2023 19:48:38 -0500 Subject: [PATCH] 4.59.1 * Fixed: Remove debug logging. * Experiment Changed: Tweak the MQTT pub/sub client to handle subscription failures better. --- package.json | 2 +- src/pubsub/index.js | 1 + src/utilities/events.js | 4 ++-- src/utilities/pubsub.js | 26 +++++++++++++++++++++++--- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 93a7d97b..ededf836 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "frankerfacez", "author": "Dan Salvato LLC", - "version": "4.59.0", + "version": "4.59.1", "description": "FrankerFaceZ is a Twitch enhancement suite.", "private": true, "license": "Apache-2.0", diff --git a/src/pubsub/index.js b/src/pubsub/index.js index 9d48ecdc..9c5b7576 100644 --- a/src/pubsub/index.js +++ b/src/pubsub/index.js @@ -140,6 +140,7 @@ export default class PubSub extends Module { const PubSubClient = await this.loadPubSubClient(); const client = this._client = new PubSubClient(cluster, { + logger: this.log.get('client'), user: user?.id ? { provider: 'twitch', id: user.id diff --git a/src/utilities/events.js b/src/utilities/events.js index 750d7203..ef66561b 100644 --- a/src/utilities/events.js +++ b/src/utilities/events.js @@ -281,8 +281,8 @@ export class EventEmitter { if ( ret instanceof Promise ) { if ( (args[0] instanceof FFZWaitableEvent) ) args[0].waitFor(ret); - else if ( this.log ) - this.log.error(`handler for event "${event}" returned a Promise but the event is not an FFZWaitableEvent`); + /*else if ( this.log ) + this.log.debug(`handler for event "${event}" returned a Promise but the event is not an FFZWaitableEvent`);*/ } if ( (args[0] instanceof FFZEvent && args[0].propagationStopped) || ret === StopPropagation ) diff --git a/src/utilities/pubsub.js b/src/utilities/pubsub.js index 83e7e7b4..475a212a 100644 --- a/src/utilities/pubsub.js +++ b/src/utilities/pubsub.js @@ -590,14 +590,34 @@ export default class PubSubClient extends EventEmitter { return Promise.resolve(); return this._client.subscribe({topicFilter: topics }) - .catch(() => { + .then(() => { + // Success. Reset the subscribe failures count. + this._sub_failures = 0; + }) + .catch(msg => { + // TODO: Check the reason why. + if ( this.logger ) + this.logger.debug('Subscribe failure for topics:', batch.join(', '), ' reason:', msg); + // If there was an error, we did NOT subscribe. for(const topic of batch) this._live_topics.delete(topic); + // See if we have more work. + if ( this._live_topics.size >= this._active_topics.size ) + return; + // Call sendSubscribes again after a bit. - if ( this._live_topics.size != this._active_topics.size ) - return sleep(2000).then(() => this._sendSubscribes()); + this._sub_failures = (this._sub_failures || 0) + 1; + + let delay = (this._sub_failures * Math.floor(Math.random() * 10) + 2) * 1000; + if ( delay > 60000 ) + delay = (Math.floor(Math.random() * 60) + 30) * 1000; + + if ( delay <= 2000 ) + delay = 2000; + + return sleep(delay).then(() => this._sendSubscribes()); }); }