mirror of https://github.com/calzoneman/sync.git
Fix bug causing channels to get stuck when DB is down
This commit is contained in:
parent
ced2719f0e
commit
8b94c54d25
|
@ -2,7 +2,7 @@
|
||||||
"author": "Calvin Montgomery",
|
"author": "Calvin Montgomery",
|
||||||
"name": "CyTube",
|
"name": "CyTube",
|
||||||
"description": "Online media synchronizer and chat",
|
"description": "Online media synchronizer and chat",
|
||||||
"version": "3.21.1",
|
"version": "3.21.2",
|
||||||
"repository": {
|
"repository": {
|
||||||
"url": "http://github.com/calzoneman/sync"
|
"url": "http://github.com/calzoneman/sync"
|
||||||
},
|
},
|
||||||
|
|
|
@ -90,6 +90,10 @@ function Channel(name) {
|
||||||
var self = this;
|
var self = this;
|
||||||
db.channels.load(this, function (err) {
|
db.channels.load(this, function (err) {
|
||||||
if (err && err !== "Channel is not registered") {
|
if (err && err !== "Channel is not registered") {
|
||||||
|
self.emit("loadFail", "Failed to load channel data from the database");
|
||||||
|
// Force channel to be unloaded, so that it will load properly when
|
||||||
|
// the database connection comes back
|
||||||
|
self.emit("empty");
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
self.initModules();
|
self.initModules();
|
||||||
|
|
|
@ -225,7 +225,9 @@ Server.prototype.unloadChannel = function (chan) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
chan.saveState();
|
chan.saveState().catch(error => {
|
||||||
|
Logger.errlog.log(`Failed to save /r/${chan.name} for unload: ${error.stack}`);
|
||||||
|
});
|
||||||
|
|
||||||
chan.logger.log("[init] Channel shutting down");
|
chan.logger.log("[init] Channel shutting down");
|
||||||
chan.logger.close();
|
chan.logger.close();
|
||||||
|
@ -358,6 +360,9 @@ Server.prototype.reloadPartitionMap = function () {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.unloadChannel(channel);
|
this.unloadChannel(channel);
|
||||||
|
}).catch(error => {
|
||||||
|
Logger.errlog.log(`Failed to unload /r/${channel.name} for ` +
|
||||||
|
`partition map flip: ${error.stack}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, 0).then(() => {
|
}, 0).then(() => {
|
||||||
|
|
10
src/user.js
10
src/user.js
|
@ -67,6 +67,16 @@ function User(socket) {
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!chan.is(Flags.C_READY)) {
|
||||||
|
chan.once("loadFail", reason => {
|
||||||
|
self.socket.emit("errorMsg", {
|
||||||
|
msg: reason,
|
||||||
|
alert: true
|
||||||
|
});
|
||||||
|
self.kick(`Channel could not be loaded: ${reason}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
chan.joinUser(self, data);
|
chan.joinUser(self, data);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue