From e526edca9203cdddafad38f823d7dfcefe440df3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Florian=20Gn=C3=A4gi?= <gnaegi@frentix.com>
Date: Mon, 1 Jul 2019 10:29:06 +0200
Subject: [PATCH] OO-4126 stop ajax poller when standby-message can not be
 loaded or poller responds with 404

---
 .../control/winmgr/_content/serverpart.html   | 27 +++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/olat/core/gui/control/winmgr/_content/serverpart.html b/src/main/java/org/olat/core/gui/control/winmgr/_content/serverpart.html
index fad15b0fddb..0e9fc7fdb05 100644
--- a/src/main/java/org/olat/core/gui/control/winmgr/_content/serverpart.html
+++ b/src/main/java/org/olat/core/gui/control/winmgr/_content/serverpart.html
@@ -95,7 +95,24 @@ function tick () {
 						if (ts > sbtimestamp) {
 							window.onunload=null;
 							window.onbeforeunload=null;
-							window.location='$sburi/';
+							## First probe if the standby window mapper is available
+							jQuery.ajax({
+								method:'get',
+								url:'$sburi/',
+								cache: false,
+								success:function() {
+									## OK, so redirect to standby
+									window.location='$sburi/';
+								},
+								error: function() {
+									## NOK: standby not available. This happens when the other opened window can not be detected
+									## (e.g. in other browser or loaded from a bookmark etc). Normally this is already done by onPollFailure,
+									## but this does not catch all cases. 
+								  	## Only solution: stop poller as this triggers some fancy ***.dms file downloads
+									o_info.poller.cancel(); 
+								}
+							})();
+							
 						}
 					} catch (e) {
 						// does not matter
@@ -127,8 +144,14 @@ function onPollSuccess(content, s, response) {
 	}
 }
 
-function onPollFailure() {
+function onPollFailure(response) {
   pollError++;
+  if(response.status == 404) { 
+	  ## Not found - happens when user opened a second window and logged in while in the first window the poller is still running. 
+	  ## Note: when in standby-mode this does not happen as the user session is still valid and the standby document exists.
+	  ## Only solution: stop poller as this triggers some fancy ***.dms file downloads
+	  o_info.poller.cancel(); 
+  }
 }
 /* ]]> */
 </script>
-- 
GitLab