summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2017-05-12 17:10:32 +0200
committerschneefux <schneefux+commit@schneefux.xyz>2017-05-12 17:10:32 +0200
commitae977a00308aa0648008c973e27231dc5e323e10 (patch)
tree8ddc9b19cfe7a4d2a4f0786b93b3599e0c320087
parentd6d157a67ea2fee48a41dada6eacb9ab6d3756f9 (diff)
downloaddiscordbot-ae977a00308aa0648008c973e27231dc5e323e10.tar.gz
discordbot-ae977a00308aa0648008c973e27231dc5e323e10.zip
fix subscription leaks
-rw-r--r--api.js12
1 files changed, 9 insertions, 3 deletions
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