diff options
author | Wu Cheng-Han | 2015-09-24 11:40:08 +0800 |
---|---|---|
committer | Wu Cheng-Han | 2015-09-24 11:40:08 +0800 |
commit | f1a0dff9e6cecf1e4e00fb6fc5e8816b88dbcb64 (patch) | |
tree | 4f1acc0b2e39aeedaf08d0432ca98e9167e3a5ba /lib | |
parent | 43a175e7100589cba393c335b5289b151982350f (diff) |
Fixed user might not disconnect from server properly, handle more uncaught exceptions
Diffstat (limited to '')
-rwxr-xr-x | lib/ot/editor-socketio-server.js | 2 | ||||
-rw-r--r-- | lib/realtime.js | 20 |
2 files changed, 16 insertions, 6 deletions
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]; } |