Skip to content

Node.js based forum software built for the modern web

guarding against Errors on Socket Disconnect

Aziz Khoury50323c3d23f5
diff --git a/src/websockets.js b/src/websockets.js
index 8d16a66c08..310af2fbc9 100644
--- a/src/websockets.js
+++ b/src/websockets.js
@@ -106,12 +106,12 @@ websockets.init = function(io) {
socket.on('disconnect', function() {
- var index = userSockets[uid].indexOf(socket);
+ var index = (userSockets[uid] || []).indexOf(socket);
if (index !== -1) {
userSockets[uid].splice(index, 1);
}
- if (userSockets[uid].length === 0) {
+ if (userSockets[uid] && userSockets[uid].length === 0) {
delete users[sessionID];
delete userSockets[uid];
if (uid) {