From 3c635c8d9886baf828dffb1f4f2c1c9cf3223fd4 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Tue, 9 Apr 2019 09:20:48 +0100 Subject: [PATCH] check version before it is modified by applyOp --- .../document-updater/app/coffee/ShareJsUpdateManager.coffee | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/document-updater/app/coffee/ShareJsUpdateManager.coffee b/services/document-updater/app/coffee/ShareJsUpdateManager.coffee index 6631c7537b..f4f3674c75 100644 --- a/services/document-updater/app/coffee/ShareJsUpdateManager.coffee +++ b/services/document-updater/app/coffee/ShareJsUpdateManager.coffee @@ -23,7 +23,8 @@ module.exports = ShareJsUpdateManager = applyUpdate: (project_id, doc_id, update, lines, version, callback = (error, updatedDocLines) ->) -> logger.log project_id: project_id, doc_id: doc_id, update: update, "applying sharejs updates" jobs = [] - + # record the update version before it is modified + incomingUpdateVersion = update.version # We could use a global model for all docs, but we're hitting issues with the # internal state of ShareJS not being accessible for clearing caches, and # getting stuck due to queued callbacks (line 260 of sharejs/server/model.coffee) @@ -44,7 +45,7 @@ module.exports = ShareJsUpdateManager = model.getSnapshot doc_key, (error, data) => return callback(error) if error? # only check hash when present and no other updates have been applied - if update.hash? and update.v == version + if update.hash? and incomingUpdateVersion == version ourHash = ShareJsUpdateManager._computeHash(data.snapshot) return callback(new Error("Invalid hash")) if ourHash != update.hash docLines = data.snapshot.split(/\r\n|\n|\r/)