diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2017-05-12 17:10:32 +0200 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2017-05-12 17:10:32 +0200 |
| commit | ae977a00308aa0648008c973e27231dc5e323e10 (patch) | |
| tree | 8ddc9b19cfe7a4d2a4f0786b93b3599e0c320087 | |
| parent | d6d157a67ea2fee48a41dada6eacb9ab6d3756f9 (diff) | |
| download | discordbot-ae977a00308aa0648008c973e27231dc5e323e10.tar.gz discordbot-ae977a00308aa0648008c973e27231dc5e323e10.zip | |
fix subscription leaks
| -rw-r--r-- | api.js | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -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 |
