Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-34210

Memory leak in Jenkins frontend when updating executors

      In ./war/src/main/webapp/scripts/hudson-behavior.js there is a memory leak triggered by replacing the HTML for the executors panel with fresh content. On installations with a huge list of executors, Chrome can increase in memory usage with over 200MBs every 10minutes by just having the Jenkins dashboard open.

      // 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 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);
                              return;
                          }
                          var p = hist.up();
      
                          var div = document.createElement('div');
                          div.innerHTML = rsp.responseText;
      
                          var node = $(div).firstDescendant();
                          p.replaceChild(node, hist);
       ########## hist cannot be garbage collected after the replaceChild!
       ########## If I comment out applySubtree(node) the memory leak disappears
       ########## So perhaps some event listeners stopping the GC from cleaning up?
                          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);
      }
      
      

          [JENKINS-34210] Memory leak in Jenkins frontend when updating executors

          Daniel Beck added a comment -

          Any idea whether this is a recent change?

          Daniel Beck added a comment - Any idea whether this is a recent change?

          Gustaf Lundh added a comment -

          danielbeck No, sorry. It is in 1.632 at least.

          I find it a bit perplexing that no-one else have reported it, since it is a huge client-side leak. I'm guessing you have access to a few large installations, can you verify the memory leak? Please know that the leak is most obvious when many builds are running on many executors. I'm guessing due to more event listeners are tied to elements in the executors table (like the build progressbar).

          /Gustaf

          Gustaf Lundh added a comment - danielbeck No, sorry. It is in 1.632 at least. I find it a bit perplexing that no-one else have reported it, since it is a huge client-side leak. I'm guessing you have access to a few large installations, can you verify the memory leak? Please know that the leak is most obvious when many builds are running on many executors. I'm guessing due to more event listeners are tied to elements in the executors table (like the build progressbar). /Gustaf

          Daniel Beck added a comment -

          I'm guessing you have access to a few large installations, can you verify the memory leak? Please know that the leak is most obvious when many builds are running on many executors.

          The installations I have access to have rather modest activity. I can still see memory for the tab rising from 102 MB to 122 MB in about 25 minutes. Not sure how to interpret this, I'm not a frontend developer.

          Daniel Beck added a comment - I'm guessing you have access to a few large installations, can you verify the memory leak? Please know that the leak is most obvious when many builds are running on many executors. The installations I have access to have rather modest activity. I can still see memory for the tab rising from 102 MB to 122 MB in about 25 minutes. Not sure how to interpret this, I'm not a frontend developer.

          I'm not sure I'm seeing this exact memory leak but I'm definitely seeing a memory leak and I'm fairly sure it's in the Jenkins frontend. Noticed Firefox was using up roughly 10% of RAM, after closing the Jenkins tab and running "Minimize memory usage" under "about:memory" it dropped to ~3%. Memory usage seems to balloon with a Jenkins tab open, I've seen usage around 50% several times.

          Robin Björklin added a comment - I'm not sure I'm seeing this exact memory leak but I'm definitely seeing a memory leak and I'm fairly sure it's in the Jenkins frontend. Noticed Firefox was using up roughly 10% of RAM, after closing the Jenkins tab and running "Minimize memory usage" under "about:memory" it dropped to ~3%. Memory usage seems to balloon with a Jenkins tab open, I've seen usage around 50% several times.

          I can provide slightly more details about where I'm seeing problems. The memory leak seems to present itself mainly when I have a job view open with the "Stage View Plugin" active. I'm seeing about the same rate of memory increase as Gustaf.

          Robin Björklin added a comment - I can provide slightly more details about where I'm seeing problems. The memory leak seems to present itself mainly when I have a job view open with the "Stage View Plugin" active. I'm seeing about the same rate of memory increase as Gustaf.

          Daniel Beck added a comment -

          rbjorklin The original issue is about the 'executors' panel in the sidebar of various views. Notably this is never shown on the same screen as Stage View Plugin's stage view. Please file a new issue for that.

          Daniel Beck added a comment - rbjorklin The original issue is about the 'executors' panel in the sidebar of various views. Notably this is never shown on the same screen as Stage View Plugin's stage view. Please file a new issue for that.

          I can't guarantee seeing the same issue, but I am regularly finding my Firefox bogging down, and I go check and find a background Jenkins tab with memory up around a gig (900M - 1.2+G). This is viewing a system with 5 slaves (with at least one usually offline), where there are usually 6-8 long running jobs going. I check on it periodically, and sometimes forget an leave a tab on it in the background.

          Darryl Champagne added a comment - I can't guarantee seeing the same issue, but I am regularly finding my Firefox bogging down, and I go check and find a background Jenkins tab with memory up around a gig (900M - 1.2+G). This is viewing a system with 5 slaves (with at least one usually offline), where there are usually 6-8 long running jobs going. I check on it periodically, and sometimes forget an leave a tab on it in the background.

          Elias Balasis added a comment -

          I am experiencing similar with Jenkins 2.479 and either on Microsoft Edge or Chrome browser.

          I am suspecting that refreshing a Jenkins page does not free all the allocated memory.
          I am saying this because I am noticing after a rather long while large amounts of memory consumed which disappear when I am closing and re-opening my Jenkins pages.

          Elias Balasis added a comment - I am experiencing similar with Jenkins 2.479 and either on Microsoft Edge or Chrome browser. I am suspecting that refreshing a Jenkins page does not free all the allocated memory. I am saying this because I am noticing after a rather long while large amounts of memory consumed which disappear when I am closing and re-opening my Jenkins pages.

            Unassigned Unassigned
            gustafl Gustaf Lundh
            Votes:
            8 Vote for this issue
            Watchers:
            14 Start watching this issue

              Created:
              Updated: