Fix race condition that might be causing errors

This commit is contained in:
Calvin Montgomery 2017-08-12 13:30:24 -07:00
parent 8a8ed0a932
commit a90d88ad65
1 changed files with 4 additions and 0 deletions

View File

@ -276,6 +276,8 @@ Channel.prototype.checkModules = function (fn, args, cb) {
const self = this; const self = this;
const refCaller = `Channel::checkModules/${fn}`; const refCaller = `Channel::checkModules/${fn}`;
this.waitFlag(Flags.C_READY, function () { this.waitFlag(Flags.C_READY, function () {
if (self.dead) return;
self.refCounter.ref(refCaller); self.refCounter.ref(refCaller);
var keys = Object.keys(self.modules); var keys = Object.keys(self.modules);
var next = function (err, result) { var next = function (err, result) {
@ -306,6 +308,7 @@ Channel.prototype.checkModules = function (fn, args, cb) {
Channel.prototype.notifyModules = function (fn, args) { Channel.prototype.notifyModules = function (fn, args) {
var self = this; var self = this;
this.waitFlag(Flags.C_READY, function () { this.waitFlag(Flags.C_READY, function () {
if (self.dead) return;
var keys = Object.keys(self.modules); var keys = Object.keys(self.modules);
keys.forEach(function (k) { keys.forEach(function (k) {
self.modules[k][fn].apply(self.modules[k], args); self.modules[k][fn].apply(self.modules[k], args);
@ -318,6 +321,7 @@ Channel.prototype.joinUser = function (user, data) {
self.refCounter.ref("Channel::user"); self.refCounter.ref("Channel::user");
self.waitFlag(Flags.C_READY, function () { self.waitFlag(Flags.C_READY, function () {
/* User closed the connection before the channel finished loading */ /* User closed the connection before the channel finished loading */
if (user.socket.disconnected) { if (user.socket.disconnected) {
self.refCounter.unref("Channel::user"); self.refCounter.unref("Channel::user");