From 99bca31766833cdbb2b692f4bf36851cc3bb59f7 Mon Sep 17 00:00:00 2001 From: James Allen Date: Thu, 19 Nov 2015 12:02:58 +0000 Subject: [PATCH] Error and hard refresh document after 30 seconds unsaved changes --- .../public/coffee/ide/editor/Document.coffee | 3 +-- .../coffee/ide/editor/ShareJsDoc.coffee | 22 +++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/services/web/public/coffee/ide/editor/Document.coffee b/services/web/public/coffee/ide/editor/Document.coffee index c7cd8c5daf..1927b791da 100644 --- a/services/web/public/coffee/ide/editor/Document.coffee +++ b/services/web/public/coffee/ide/editor/Document.coffee @@ -242,8 +242,7 @@ define [ 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() + @_onError new Error("op timed out"), {op: op} @doc.on "flush", (inflightOp, pendingOp, version) => @ide.pushEvent "flush", doc_id: @doc_id, diff --git a/services/web/public/coffee/ide/editor/ShareJsDoc.coffee b/services/web/public/coffee/ide/editor/ShareJsDoc.coffee index 7d5b6106c6..d67961bdf8 100644 --- a/services/web/public/coffee/ide/editor/ShareJsDoc.coffee +++ b/services/web/public/coffee/ide/editor/ShareJsDoc.coffee @@ -109,8 +109,9 @@ define [ attachToAce: (ace) -> @_doc.attach_ace(ace, false, window.maxDocLength) detachFromAce: () -> @_doc.detach_ace?() - INFLIGHT_OP_TIMEOUT: 5000 + INFLIGHT_OP_TIMEOUT: 5000 # Retry sending ops after 5 seconds without an ack _startInflightOpTimeout: (update) -> + @_startFatalTimeoutTimer(update) timer = setTimeout () => # Only send the update again if inflightOp is still populated # This can be cleared when hard reloading the document in which @@ -124,13 +125,26 @@ define [ # one or more disconnects, or if it was submitted during the current session. update.dupIfSource = [@connection.id, @_doc.inflightSubmittedIds...] @connection.send(update) - # TODO: Trigger op:timeout only when some max retries have been hit - # and we need to do a full reload. - # @trigger "op:timeout", update , @INFLIGHT_OP_TIMEOUT @_doc.inflightCallbacks.push () => + @_clearFatalTimeoutTimer() clearTimeout timer + FATAL_OP_TIMEOUT: 30000 # 30 seconds + _startFatalTimeoutTimer: (update) -> + # If an op doesn't get acked within FATAL_OP_TIMEOUT, something has + # gone unrecoverably wrong (the op will have been retried multiple times) + return if @_timeoutTimer? + @_timeoutTimer = setTimeout () => + @_clearFatalTimeoutTimer() + @trigger "op:timeout", update + , @FATAL_OP_TIMEOUT + + _clearFatalTimeoutTimer: () -> + return if !@_timeoutTimer? + clearTimeout @_timeoutTimer + @_timeoutTimer = null + _handleError: (error, meta = {}) -> @trigger "error", error, meta