Memory leak in progressive log

This issue is archived. You can view it, but you can't modify it. Learn more

XMLWordPrintable

      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

            Assignee:
            Unassigned
            Reporter:
            Lucie Votypkova
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Archived: