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",
|
||||
"name": "CyTube",
|
||||
"description": "Online media synchronizer and chat",
|
||||
"version": "3.21.1",
|
||||
"version": "3.21.2",
|
||||
"repository": {
|
||||
"url": "http://github.com/calzoneman/sync"
|
||||
},
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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(() => {
|
||||
|
|
10
src/user.js
10
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);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue