diff --git a/lib/ot/editor-socketio-server.js b/lib/ot/editor-socketio-server.js index 67920cbf..1b2529be 100755 --- a/lib/ot/editor-socketio-server.js +++ b/lib/ot/editor-socketio-server.js @@ -51,7 +51,7 @@ EditorSocketIOServer.prototype.addClient = function (socket) { try { self.onOperation(socket, revision, operation, selection); } catch (err) { - socket.disconnect(); + socket.disconnect(true); } }); }); diff --git a/lib/realtime.js b/lib/realtime.js index 1e1f0107..af33cadf 100644 --- a/lib/realtime.js +++ b/lib/realtime.js @@ -171,9 +171,12 @@ function getStatus(callback) { } function getNotenameFromSocket(socket) { + if (!socket || !socket.handshake || !socket.handshake.headers) { + return; + } var referer = socket.handshake.headers.referer; if (!referer) { - return socket.disconnect(); + return socket.disconnect(true); } var hostUrl = url.parse(referer); var notename = hostUrl.pathname.split('/')[1]; @@ -184,7 +187,7 @@ function getNotenameFromSocket(socket) { socket.emit('info', { code: 404 }); - return socket.disconnect(); + return socket.disconnect(true); } notename = LZString.decompressFromBase64(notename); return notename; @@ -281,7 +284,10 @@ function startConnection(socket) { isConnectionBusy = true; var notename = getNotenameFromSocket(socket); - if (!notename) return; + if (!notename) { + isConnectionBusy = false; + return; + } if (!notes[notename]) { db.readFromDB(notename, function (err, data) { @@ -289,7 +295,7 @@ function startConnection(socket) { socket.emit('info', { code: 404 }); - socket.disconnect(); + socket.disconnect(true); //clear err socket in queue for (var i = 0; i < connectionSocketQueue.length; i++) { if (connectionSocketQueue[i].id == socket.id) @@ -306,6 +312,7 @@ function startConnection(socket) { Note.findOrNewNote(notename, permission, function (err, note) { if (err) { responseError(res, "404", "Not Found", "oops."); + isConnectionBusy = false; return; } var body = LZString.decompressFromBase64(data.rows[0].content); @@ -338,7 +345,10 @@ function disconnect(socket) { logger.info(JSON.stringify(users[socket.id])); } var notename = getNotenameFromSocket(socket); - if (!notename) return; + if (!notename) { + isDisconnectBusy = false; + return; + } if (users[socket.id]) { delete users[socket.id]; }