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

Memory leak in progressive log

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Critical Critical
    • core

      Hi,
      I found memory leak in stapler in class
      https://github.com/stapler/stapler/blob/master/core/src/main/java/org/kohsuke/stapler/framework/io/LargeText.java

      the problem is caused by condition on row 213.

              if(completed) {
                  // write everything till EOF
                  byte[] buf = new byte[1024];
                  int sz;
                  while((sz=f.read(buf))>=0)
                      os.write(buf,0,sz);
             }
      

      Unfortunately the fact that building is finished does not mean that we can write everything what remains.
      Our Jenkins instance fell due to this bug. The scenario is quite easy (especially in case of smartfrog plugin where is used only full console, no skipping bytes).
      1. Run job which creates a great log (several GB)
      2. Open a log console of running build which log has had already several GB)
      3. Open full console (without skipping bytes) and let it open in browser
      4. Stop this build (so the log is finished and completed in aforementioned code is true)
      5. You get out of memory (in case that your application has less memory then the size of log), because whole log which was not written is written in one shot to the memory because used output stream is in this case class CharSpool which write everything into memory.

      I suggest not to use completed and write the rest of log in the same way as it is done with completed=false.

      Please add your opinions into comments. Thanks

            Unassigned Unassigned
            lvotypkova Lucie Votypkova
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: