Merge pull request #12229 from overleaf/jpa-reject-decrement-doc-version

[docstore] reject doc updates that decrement the doc version

GitOrigin-RevId: 533cc5ece8d5684c85b2f63fa2a093c68f6b5877
This commit is contained in:
Jakob Ackermann
2023-03-22 09:04:55 +00:00
committed by Copybot
parent 90a921cbe6
commit e4efe121da
5 changed files with 72 additions and 0 deletions
+10
View File
@@ -263,6 +263,16 @@ module.exports = DocManager = {
updateVersion = true
updateRanges = true
} else {
if (doc.version > version) {
// Reject update when the version was decremented.
// Potential reasons: racing flush, broken history.
return callback(
new Errors.DocVersionDecrementedError('rejecting stale update', {
updateVersion: version,
flushedVersion: doc.version,
})
)
}
updateLines = !_.isEqual(doc.lines, lines)
updateVersion = doc.version !== version
updateRanges = RangeManager.shouldUpdateRanges(doc.ranges, ranges)