Просмотр исходного кода

[ShareJsUpdateManager] double check doc size before flushing

Jakob Ackermann 5 лет назад
Родитель
Сommit
a4ae0ea12f
1 измененных файлов с 14 добавлено и 0 удалено
  1. 14 0
      services/document-updater/app/js/ShareJsUpdateManager.js

+ 14 - 0
services/document-updater/app/js/ShareJsUpdateManager.js

@@ -87,6 +87,20 @@ module.exports = ShareJsUpdateManager = {
         if (error != null) {
           return callback(error)
         }
+        const docSizeAfter = data.snapshot.length
+        if (docSizeAfter > Settings.max_doc_length) {
+          const docSizeBefore = lines.join('\n').length
+          const err = new Error(
+            'blocking persistence of ShareJs update: doc size exceeds limits'
+          )
+          logger.error(
+            { project_id, doc_id, err, docSizeBefore, docSizeAfter },
+            err.message
+          )
+          metrics.inc('sharejs.other-error')
+          const publicError = 'Update takes doc over max doc size'
+          return callback(publicError)
+        }
         // only check hash when present and no other updates have been applied
         if (update.hash != null && incomingUpdateVersion === version) {
           const ourHash = ShareJsUpdateManager._computeHash(data.snapshot)