diff --git a/index.js b/index.js index 8a22f774..a109afe3 100644 --- a/index.js +++ b/index.js @@ -126,3 +126,8 @@ if (Config.get("service-socket.enabled")) { var server = new ServiceSocket; server.init(handleLine, Config.get("service-socket.socket")); } + +require("bluebird"); +process.on("unhandledRejection", function (reason, promise) { + Logger.errlog.log("[SEVERE] Unhandled rejection: " + reason.stack); +}); diff --git a/package.json b/package.json index f0099b72..c025ada2 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Calvin Montgomery", "name": "CyTube", "description": "Online media synchronizer and chat", - "version": "3.25.1", + "version": "3.25.2", "repository": { "url": "http://github.com/calzoneman/sync" }, diff --git a/src/bgtask.js b/src/bgtask.js index 7cb6ab4c..197893e3 100644 --- a/src/bgtask.js +++ b/src/bgtask.js @@ -63,15 +63,24 @@ function initChannelDumper(Server) { * 60000; setInterval(function () { var wait = CHANNEL_SAVE_INTERVAL / Server.channels.length; + Logger.syslog.log(`Saving channels with delay ${wait}`); Promise.reduce(Server.channels, (_, chan) => { return Promise.delay(wait).then(() => { + if (chan.name === 'test') + throw new TypeError('Whoops fucked up there'); if (!chan.dead && chan.users && chan.users.length > 0) { - return chan.saveState().catch(err => { + return chan.saveState().tap(() => { + Logger.syslog.log(`Saved /r/${chan.name}`); + }).catch(err => { Logger.errlog.log(`Failed to save /r/${chan.name}: ${err.stack}`); }); } + }).catch(error => { + Logger.errlog.log(`Failed to save channel: ${error.stack}`); }); - }, 0); + }, 0).catch(error => { + Logger.errlog.log(`Failed to save channels: ${error.stack}`); + }); }, CHANNEL_SAVE_INTERVAL); } diff --git a/src/server.js b/src/server.js index fb0fd9be..ca93bf8a 100644 --- a/src/server.js +++ b/src/server.js @@ -319,11 +319,15 @@ Server.prototype.setAnnouncement = function (data) { Server.prototype.shutdown = function () { Logger.syslog.log("Unloading channels"); Promise.map(this.channels, channel => { - return channel.saveState().tap(() => { - Logger.syslog.log(`Saved /r/${channel.name}`); - }).catch(err => { - Logger.errlog.log(`Failed to save /r/${channel.name}: ${err.stack}`); - }); + try { + return channel.saveState().tap(() => { + Logger.syslog.log(`Saved /r/${channel.name}`); + }).catch(err => { + Logger.errlog.log(`Failed to save /r/${channel.name}: ${err.stack}`); + }); + } catch (error) { + Logger.errlog.log(`Failed to save channel: ${error.stack}`); + } }, { concurrency: 5 }).then(() => { Logger.syslog.log("Goodbye"); process.exit(0);