From 6ea58d4d6c72225ca55acc09c9f8692e25dff1bb Mon Sep 17 00:00:00 2001 From: James Allen Date: Thu, 26 May 2016 13:55:53 +0100 Subject: [PATCH] Don't try to resend an update if the editor is not joined to the project --- .../public/coffee/ide/editor/ShareJsDoc.coffee | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/services/web/public/coffee/ide/editor/ShareJsDoc.coffee b/services/web/public/coffee/ide/editor/ShareJsDoc.coffee index ae07a8ca7a..27d325676c 100644 --- a/services/web/public/coffee/ide/editor/ShareJsDoc.coffee +++ b/services/web/public/coffee/ide/editor/ShareJsDoc.coffee @@ -112,12 +112,14 @@ define [ detachFromAce: () -> @_doc.detach_ace?() INFLIGHT_OP_TIMEOUT: 5000 # Retry sending ops after 5 seconds without an ack + WAIT_FOR_CONNECTION_TIMEOUT: 500 # If we're waiting for the project to join, try again in 0.5 seconds _startInflightOpTimeout: (update) -> @_startFatalTimeoutTimer(update) - timer = setTimeout () => + retryOp = () => # Only send the update again if inflightOp is still populated # This can be cleared when hard reloading the document in which # case we don't want to keep trying to send it. + sl_console.log "[inflightOpTimeout] Trying op again" if @_doc.inflightOp? # When there is a socket.io disconnect, @_doc.inflightSubmittedIds # is updated with the socket.io client id of the current op in flight @@ -126,8 +128,18 @@ define [ # So we need both depending on whether the op was submitted before # one or more disconnects, or if it was submitted during the current session. update.dupIfSource = [@connection.id, @_doc.inflightSubmittedIds...] - @connection.send(update) - , @INFLIGHT_OP_TIMEOUT + + # We must be joined to a project for applyOtUpdate to work on the real-time + # service, so don't send an op if we're not. Connection state is set to 'ok' + # when we've joined the project + if @connection.state != "ok" + sl_console.log "[inflightOpTimeout] Not connected, retrying in 0.5s" + timer = setTimeout retryOp, @WAIT_FOR_CONNECTION_TIMEOUT + else + sl_console.log "[inflightOpTimeout] Sending" + @connection.send(update) + + timer = setTimeout retryOp, @INFLIGHT_OP_TIMEOUT @_doc.inflightCallbacks.push () => @_clearFatalTimeoutTimer() clearTimeout timer