From 024ee7913e5319f0e76ca7a875a7698a7e057462 Mon Sep 17 00:00:00 2001 From: reality Date: Tue, 7 Jul 2015 17:45:12 +0000 Subject: [PATCH] fix race condition in getting flag stack --- modules/atheme/atheme.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/modules/atheme/atheme.js b/modules/atheme/atheme.js index 9ab1502..0dc0c9c 100644 --- a/modules/atheme/atheme.js +++ b/modules/atheme/atheme.js @@ -17,12 +17,13 @@ var atheme = function(dbot) { } else { this.flagStack[server][channel] = { 'flags': {}, - 'callbacks': [ callback ] + 'callbacks': [ callback ], + 'timeout': null }; } dbot.say(server, 'chanserv', 'FLAGS ' + channel); - setTimeout(function() { // Delete callback if no response + this.flagStack[server][channel].timeout = setTimeout(function() { // Delete callback if no response if(_.has(this.flagStack[server], channel)) { _.each(this.flagStack[server][channel].callbacks, function(callback) { callback(true, null); @@ -95,7 +96,7 @@ var atheme = function(dbot) { delete allFlags[u]; } }); - async.each(_.keys(hostMasks), function(hostMask, done) { + async.each(_.keys(hostMasks), function(hostMask, done) { this.api.getVHosts(event.server, hostMask.split('@')[1], function(err, users) { _.each(users, function(user) { allFlags[user] = hostMasks[hostMask]; @@ -103,12 +104,12 @@ var atheme = function(dbot) { done(); }); }.bind(this), function() { - console.log('DONE'); - _.each(this.flagStack[event.server][end[1]].callbacks, function(callback) { - callback(null, this.flagStack[event.server][end[1]].flags); - }.bind(this)); - delete this.flagStack[event.server][end[1]]; - }.bind(this)); + _.each(this.flagStack[event.server][end[1]].callbacks, function(callback) { + callback(null, this.flagStack[event.server][end[1]].flags); + }.bind(this)); + clearTimeout(this.flagStack[event.server][end[1]].timeout); + delete this.flagStack[event.server][end[1]]; + }.bind(this)); } } } else if(event.user === 'HostServ') {