diff --git a/lib/client/doc.js b/lib/client/doc.js index 7a1e7d0b..3695a9ea 100644 --- a/lib/client/doc.js +++ b/lib/client/doc.js @@ -1058,6 +1058,8 @@ Doc.prototype._hardRollback = function(err) { // Fetch the latest version from the server to get us back into a working state var doc = this; this._fetch({force: true}, function(fetchError) { + doc._isInHardRollback = false; + // We want to check that no errors are swallowed, so we check that: // - there are callbacks to call, and // - that every single pending op called a callback @@ -1088,10 +1090,8 @@ Doc.prototype._hardRollback = function(err) { inflightOp = null; } - if (!pendingOps.length) { - doc._isInHardRollback = false; - return; - } + if (!pendingOps.length) return; + err = new ShareDBError( ERROR_CODE.ERR_PENDING_OP_REMOVED_BY_OP_SUBMIT_REJECTED, 'Discarding pending op because of hard rollback during ERR_OP_SUBMIT_REJECTED' @@ -1104,7 +1104,6 @@ Doc.prototype._hardRollback = function(err) { allOpsHadCallbacks = util.callEach(pendingOps[i].callbacks, err) && allOpsHadCallbacks; } if (err && !allOpsHadCallbacks) doc.emit('error', err); - doc._isInHardRollback = false; }); };