diff --git a/package.json b/package.json index 705aad79..9f1bb452 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Calvin Montgomery", "name": "CyTube", "description": "Online media synchronizer and chat", - "version": "3.21.1", + "version": "3.21.2", "repository": { "url": "http://github.com/calzoneman/sync" }, diff --git a/src/channel/channel.js b/src/channel/channel.js index df1f55d2..3bac4fe6 100644 --- a/src/channel/channel.js +++ b/src/channel/channel.js @@ -90,6 +90,10 @@ function Channel(name) { var self = this; db.channels.load(this, function (err) { 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; } else { self.initModules(); diff --git a/src/server.js b/src/server.js index 593e21b4..4821e4a1 100644 --- a/src/server.js +++ b/src/server.js @@ -225,7 +225,9 @@ Server.prototype.unloadChannel = function (chan) { 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.close(); @@ -358,6 +360,9 @@ Server.prototype.reloadPartitionMap = function () { } }); this.unloadChannel(channel); + }).catch(error => { + Logger.errlog.log(`Failed to unload /r/${channel.name} for ` + + `partition map flip: ${error.stack}`); }); } }, 0).then(() => { diff --git a/src/user.js b/src/user.js index e2bd66e8..62826b5d 100644 --- a/src/user.js +++ b/src/user.js @@ -67,6 +67,16 @@ function User(socket) { }); 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); }); });