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

Merge pull request #5625 from overleaf/jpa-block-update-loop

[web] block a loop of failing rootDoc update requests

GitOrigin-RevId: 1388024fc125ee1e80e45a7bbbc787306cb60d1d
Jakob Ackermann 4 лет назад
Родитель
Сommit
8ba1803972

+ 20 - 3
services/web/frontend/js/ide/settings/controllers/SettingsController.js

@@ -184,6 +184,7 @@ export default App.controller(
       }
     })
 
+    let rootDocUpdateFailed = 0
     $scope.$watch('project.rootDoc_id', (rootDoc_id, oldRootDoc_id) => {
       if (this.ignoreUpdates) {
         return
@@ -200,9 +201,25 @@ export default App.controller(
       }
       // otherwise only save changes, null values are allowed
       if (rootDoc_id !== oldRootDoc_id) {
-        settings.saveProjectSettings({ rootDocId: rootDoc_id }).catch(() => {
-          $scope.project.rootDoc_id = oldRootDoc_id
-        })
+        settings
+          .saveProjectSettings({ rootDocId: rootDoc_id })
+          .then(() => {
+            rootDocUpdateFailed = 0
+          })
+          .catch(() => {
+            rootDocUpdateFailed++
+            // Let the login redirect run (if any) and reset afterwards.
+            setTimeout(() => {
+              if (rootDocUpdateFailed > 10) {
+                // We are in a loop of failing updates. Stop now.
+                this.ignoreUpdates = true
+              }
+              $scope.$apply(() => {
+                $scope.project.rootDoc_id = oldRootDoc_id
+              })
+              this.ignoreUpdates = false
+            })
+          })
       }
     })