Skip to content

Commit

Permalink
Fix destructuring error when unsubscribing without subscribing (masto…
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargron authored and thenameisnigel-old committed Sep 7, 2020
1 parent 5bacb28 commit b48b347
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions streaming/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ const startWorker = (workerId) => {
if (subs[channel].length === 0) {
log.verbose(`Unsubscribe ${channel}`);
redisSubscribeClient.unsubscribe(channel);
delete subs[channel];
}
};

Expand Down Expand Up @@ -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() }));
Expand Down

0 comments on commit b48b347

Please sign in to comment.