Error and hard refresh document after 30 seconds unsaved changes

This commit is contained in:
James Allen 2015-11-19 12:02:58 +00:00
parent bf452bf306
commit 99bca31766
2 changed files with 19 additions and 6 deletions

View file

@ -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,

View file

@ -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