From ae977a00308aa0648008c973e27231dc5e323e10 Mon Sep 17 00:00:00 2001 From: schneefux Date: Fri, 12 May 2017 17:10:32 +0200 Subject: fix subscription leaks --- api.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'api.js') diff --git a/api.js b/api.js index 7dc7b44..f5ae41c 100644 --- a/api.js +++ b/api.js @@ -16,7 +16,7 @@ let cache = cacheManager.caching({ ttl: 10 // s }); -const UPDATE_TIMEOUT = parseInt(process.env.UPDATE_TIMEOUT) || 60; // s +const UPDATE_TIMEOUT = parseInt(process.env.UPDATE_TIMEOUT) || 30; // s const API_FE_URL = process.env.API_FE_URL || "http://vainsocial.bot/bot/api", API_MAP_URL = process.env.API_MAP_URL || "http://vainsocial.dev/masters/", @@ -138,7 +138,10 @@ module.exports.subscribeUpdates = (name, timeout=UPDATE_TIMEOUT) => { subscription = subscribe("player." + name, channel); // stop updates after timeout - setTimeout(() => channel.close(), timeout*1000); + setTimeout(() => { + channel.close(); + subscription.unsubscribe(); + }, timeout*1000); let msg; return { next: async () => { @@ -154,16 +157,19 @@ module.exports.subscribeUpdates = (name, timeout=UPDATE_TIMEOUT) => { } if (msg == "search_fail") { subscription.unsubscribe(); + channel.close(); throw { error: { err: "No player found for the provided IGN." } }; } if (msg == Channel.DONE) { subscription.unsubscribe(); + channel.close(); return undefined; } return msg; - } }; + }, stop: async () => channel.close(); + }; } // search an unknown player -- cgit v1.3.1