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

transient file handle leak in LargeText.GzipAwareSession.isGzipStream(File)

      One of the "reproduction" scenarios if JENKINS-45057 identified a separate transient file handle leak in LargeText.GzipAwareSession.isGzipStream(File)

          [JENKINS-45903] transient file handle leak in LargeText.GzipAwareSession.isGzipStream(File)

          Stephen Connolly created issue -

          Reproduction test:

          Run freestyle job with system groovy step:

          import hudson.model.*
          
          def thr = Thread.currentThread()
          def build = thr?.executable
          def jobName = build.parent.builds[0].properties.get("envVars").get("JOB_NAME")
          def jobNr = build.parent.builds[0].properties.get("envVars").get("BUILD_NUMBER")
          println "This is " + jobName + " running for the $jobNr:th time"
          

          Now the above script is not a correct script, but use of Groovy's magic "proprerties" property exposes the file leak when instantiating the Run.getLogText() "property", you get file handle leaks like:

          > java 19008 jenkins 587r REG 252,0 503 395865 /data/jenkins/jobs/automation/jobs/test-open-files/builds/7/log
          > java 19008 jenkins 589r REG 252,0 503 395865 /data/jenkins/jobs/automation/jobs/test-open-files/builds/7/log
          > java 19008 jenkins 590r REG 252,0 503 395865 /data/jenkins/jobs/automation/jobs/test-open-files/builds/7/log
          > java 19008 jenkins 592r REG 252,0 503 395865 /data/jenkins/jobs/automation/jobs/test-open-files/builds/7/log
          

          The differentiator from JENKINS-45057 is that these are READ locks not WRITE locks.

          Stephen Connolly added a comment - Reproduction test: Run freestyle job with system groovy step: import hudson.model.* def thr = Thread .currentThread() def build = thr?.executable def jobName = build.parent.builds[0].properties.get( "envVars" ).get( "JOB_NAME" ) def jobNr = build.parent.builds[0].properties.get( "envVars" ).get( "BUILD_NUMBER" ) println "This is " + jobName + " running for the $jobNr:th time" Now the above script is not a correct script, but use of Groovy's magic "proprerties" property exposes the file leak when instantiating the Run.getLogText() "property", you get file handle leaks like: > java 19008 jenkins 587r REG 252,0 503 395865 /data/jenkins/jobs/automation/jobs/test-open-files/builds/7/log > java 19008 jenkins 589r REG 252,0 503 395865 /data/jenkins/jobs/automation/jobs/test-open-files/builds/7/log > java 19008 jenkins 590r REG 252,0 503 395865 /data/jenkins/jobs/automation/jobs/test-open-files/builds/7/log > java 19008 jenkins 592r REG 252,0 503 395865 /data/jenkins/jobs/automation/jobs/test-open-files/builds/7/log The differentiator from JENKINS-45057 is that these are READ locks not WRITE locks.
          Stephen Connolly made changes -
          Remote Link New: This issue links to "stapler#124 (Web Link)" [ 17380 ]
          Stephen Connolly made changes -
          Link New: This issue is related to JENKINS-45057 [ JENKINS-45057 ]
          Stephen Connolly made changes -
          Link New: This issue is related to JENKINS-42934 [ JENKINS-42934 ]
          Stephen Connolly made changes -
          Assignee New: Stephen Connolly [ stephenconnolly ]

          Joschua Grube added a comment - - edited

          We solved this by using this approach instead:

          def thr = Thread.currentThread()
          def build = thr?.executable
          def resolver = build.buildVariableResolver
          def envValue = resolver.resolve(envName)

          Checkout: https://wiki.jenkins.io/display/JENKINS/Parameterized+System+Groovy+script

          Note: This just works for system groovy scripts.

          Joschua Grube added a comment - - edited We solved this by using this approach instead: def thr = Thread .currentThread() def build = thr?.executable def resolver = build.buildVariableResolver def envValue = resolver.resolve(envName) Checkout:  https://wiki.jenkins.io/display/JENKINS/Parameterized+System+Groovy+script Note: This just works for system groovy scripts.

          joschua_grube yes there are many ways to fix the groovy script, the groovy script is just cited as a reproducer...

          Stephen Connolly added a comment - joschua_grube yes there are many ways to fix the groovy script, the groovy script is just cited as a reproducer...
          Oleg Nenashev made changes -
          Labels New: stapler

          Oleg Nenashev added a comment -

          The fix has been integrated towards Jenkins 2.74. Marking it as LTS Candidate, but I am not sure we want to backport Stapler

          Oleg Nenashev added a comment - The fix has been integrated towards Jenkins 2.74. Marking it as LTS Candidate, but I am not sure we want to backport Stapler
          Oleg Nenashev made changes -
          Resolution New: Fixed [ 1 ]
          Status Original: Open [ 1 ] New: Resolved [ 5 ]

            stephenconnolly Stephen Connolly
            stephenconnolly Stephen Connolly
            Votes:
            2 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: