diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2020-08-12 15:36:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-12 15:36:07 +0200 |
commit | 01647b8acb0d881609e1d6729e01e373a11030fb (patch) | |
tree | 355857b160893c03ce83a5c073f3b1dfa030656f | |
parent | 8d217d7231be46af552c63aff9e53d0ed5dca0f6 (diff) |
Fix destructuring error when unsubscribing without subscribing (#14566)
-rw-r--r-- | streaming/index.js | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/streaming/index.js b/streaming/index.js index 7c0c6a465..7072d0bd7 100644 --- a/streaming/index.js +++ b/streaming/index.js @@ -210,6 +210,7 @@ const startWorker = (workerId) => { if (subs[channel].length === 0) { log.verbose(`Unsubscribe ${channel}`); redisSubscribeClient.unsubscribe(channel); + delete subs[channel]; } }; @@ -866,19 +867,21 @@ const startWorker = (workerId) => { channelNameToIds(request, channelName, params).then(({ channelIds }) => { log.verbose(request.requestId, `Ending stream from ${channelIds.join(', ')} for ${request.accountId}`); - const { listener, stopHeartbeat } = subscriptions[channelIds.join(';')]; + const subscription = subscriptions[channelIds.join(';')]; - if (!listener) { + if (!subscription) { return; } + const { listener, stopHeartbeat } = subscription; + channelIds.forEach(channelId => { unsubscribe(`${redisPrefix}${channelId}`, listener); }); stopHeartbeat(); - subscriptions[channelIds.join(';')] = undefined; + delete subscriptions[channelIds.join(';')]; }).catch(err => { log.verbose(request.requestId, 'Unsubscription error:', err); socket.send(JSON.stringify({ error: err.toString() })); |