Skip to content

Commit

Permalink
[JENKINS-10912] Use setInterval in refreshPart (#2539)
Browse files Browse the repository at this point in the history
* [JENKINS-10912] Use setInterval in refreshPart

The current implementation of refreshPart creates a new closure every 5
seconds, which, in combination with XMLHttpRequest objects, results in a
significant memory leak in all major browsers. By using
window.setInterval to schedule periodic refreshes, only one closure per
id is created. Please see issue #10912 in the Jenkins tracker for
further details.

* Stop periodical calls if we can't find the div

* Don't check if isRunAsTest changed after page load

(cherry picked from commit 096614a)
  • Loading branch information
lpancescu authored and olivergondza committed Nov 3, 2016
1 parent 1875144 commit 2f0632a
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions war/src/main/webapp/scripts/hudson-behavior.js
Expand Up @@ -1486,13 +1486,16 @@ function expandTextArea(button,id) {
// refresh a part of the HTML specified by the given ID,
// by using the contents fetched from the given URL.
function refreshPart(id,url) {
var intervalID = null;
var f = function() {
if(isPageVisible()) {
new Ajax.Request(url, {
onSuccess: function(rsp) {
var hist = $(id);
if (hist == null) {
console.log("There's no element that has ID of " + id);
if (intervalID !== null)
window.clearInterval(intervalID);
return;
}
var p = hist.up();
Expand All @@ -1505,22 +1508,14 @@ function refreshPart(id,url) {

Behaviour.applySubtree(node);
layoutUpdateCallback.call();

if(isRunAsTest) return;
refreshPart(id,url);
}
});
} else {
// Reschedule
if(isRunAsTest) return;
refreshPart(id,url);
});
}

};
// if run as test, just do it once and do it now to make sure it's working,
// but don't repeat.
if(isRunAsTest) f();
else window.setTimeout(f, 5000);
else intervalID = window.setInterval(f, 5000);
}


Expand Down

0 comments on commit 2f0632a

Please sign in to comment.