From 8ba180397242ba316042e89f498d1c3d8612dc7b Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Tue, 2 Nov 2021 11:33:39 +0100 Subject: [PATCH] Merge pull request #5625 from overleaf/jpa-block-update-loop [web] block a loop of failing rootDoc update requests GitOrigin-RevId: 1388024fc125ee1e80e45a7bbbc787306cb60d1d --- .../controllers/SettingsController.js | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/services/web/frontend/js/ide/settings/controllers/SettingsController.js b/services/web/frontend/js/ide/settings/controllers/SettingsController.js index 70954bdeec..c4e0b4c6b9 100644 --- a/services/web/frontend/js/ide/settings/controllers/SettingsController.js +++ b/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 + }) + }) } })