From 72dbefc5ad4f30ae45b686759ab4b2da263e8108 Mon Sep 17 00:00:00 2001 From: James Allen Date: Wed, 2 Apr 2014 16:16:07 +0100 Subject: [PATCH] Resync after an op is not acknowledged rather than throwing an error --- services/web/public/coffee/editor/Document.coffee | 12 ++++++++++++ services/web/public/coffee/editor/ShareJsDoc.coffee | 2 +- .../web/public/coffee/ide/ConnectionManager.coffee | 7 +++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/services/web/public/coffee/editor/Document.coffee b/services/web/public/coffee/editor/Document.coffee index a316ab5961..56c3aa384f 100644 --- a/services/web/public/coffee/editor/Document.coffee +++ b/services/web/public/coffee/editor/Document.coffee @@ -87,6 +87,11 @@ define [ wantToBeJoined: @wantToBeJoined update: update + if Math.random() < (@ide.disconnectRate or 0) + console.log "Simulating disconnect" + @ide.connectionManager.disconnect() + return + if update?.doc == @doc_id and @doc? @doc.processUpdateFromServer update @@ -163,6 +168,13 @@ define [ doc_id: @doc_id op: op @trigger "op:acknowledged" + @doc.on "op:timeout", (op) => + @ide.pushEvent "op:timeout", + doc_id: @doc_id + op: op + @trigger "op:timeout" + ga?('send', 'event', 'error', "op timeout", "Op was now acknowledged - #{ide.socket.socket.transport.name}" ) + @ide.connectionManager.reconnectImmediately() @doc.on "flush", (inflightOp, pendingOp, version) => @ide.pushEvent "flush", doc_id: @doc_id, diff --git a/services/web/public/coffee/editor/ShareJsDoc.coffee b/services/web/public/coffee/editor/ShareJsDoc.coffee index 1a0f2e9f02..04485c9602 100644 --- a/services/web/public/coffee/editor/ShareJsDoc.coffee +++ b/services/web/public/coffee/editor/ShareJsDoc.coffee @@ -98,7 +98,7 @@ define [ v: update.v op_sent_at: new Date() timer = setTimeout () => - @_handleError new Error("Doc op was not acknowledged in time"), meta + @trigger "op:timeout", update , @INFLIGHT_OP_TIMEOUT @_doc.inflightCallbacks.push () => clearTimeout timer diff --git a/services/web/public/coffee/ide/ConnectionManager.coffee b/services/web/public/coffee/ide/ConnectionManager.coffee index c9f5e6a800..ae54c7946b 100644 --- a/services/web/public/coffee/ide/ConnectionManager.coffee +++ b/services/web/public/coffee/ide/ConnectionManager.coffee @@ -33,6 +33,13 @@ define [ e.preventDefault() @tryReconnect() @hideModal() + + reconnectImmediately: () -> + @disconnect() + @tryReconnect() + + disconnect: () -> + @socket.disconnect() showModalAndStartAutoReconnect: () -> @hideModal()