From 29be9233e936e01a072ecb923a023f5417e908f3 Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Mon, 11 Dec 2017 22:46:41 -0800 Subject: [PATCH] Add check for weird setAFK edge case --- package.json | 2 +- src/user.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 8ab6976b..38336772 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Calvin Montgomery", "name": "CyTube", "description": "Online media synchronizer and chat", - "version": "3.51.9", + "version": "3.51.10", "repository": { "url": "http://github.com/calzoneman/sync" }, diff --git a/src/user.js b/src/user.js index 642cb9a8..e43c1c79 100644 --- a/src/user.js +++ b/src/user.js @@ -242,6 +242,21 @@ User.prototype.setAFK = function (afk) { this.autoAFK(); } + if (!this.inChannel()) { + // I haven't exactly nailed down why this.channel can + // become null halfway through the function, but based + // on log analysis I suspect it's because this.socket.emit() + // can fire the "disconnect" event which then tears down + // the User object. + LOGGER.warn( + "Encountered this.channel == null from setAFK. " + + "this.dead=%t this.flags=%b", + this.dead, + this.flags + ); + return; + } + /* Number of AFK users changed, voteskip state changes */ if (this.channel.modules.voteskip) { this.channel.modules.voteskip.update();