]> cat aescling's git repositories - mastodon.git/commitdiff
Fix destructuring error when unsubscribing without subscribing (#14566)
authorEugen Rochko <eugen@zeonfederated.com>
Wed, 12 Aug 2020 13:36:07 +0000 (15:36 +0200)
committerGitHub <noreply@github.com>
Wed, 12 Aug 2020 13:36:07 +0000 (15:36 +0200)
streaming/index.js

index 7c0c6a465eb37c86c7df32e9f19b002ccf8aca53..7072d0bd7678bf2005053f86a7f66dec9d8b8eef 100644 (file)
@@ -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() }));