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

Memory leak in build-timeout-plugin when used with NoActivityTimeOutStrategy

      When using the NoActivityTimeOutStrategy the plugin spawns new instances of hudson.plugins.build_timeout.BuildTimeoutWrapper$EnvironmentImpl$TimeoutTimerTask and cancles the previous TimerTask.
      However cancelled TimerTasks are not removed from the Timer until they get to the time that they should execute and so for a long running build (days) generating lots of IO with large breaks - and a long inactivity time-out (1 day) you will end up with millions of these TimeoutTimerTask

          [JENKINS-31627] Memory leak in build-timeout-plugin when used with NoActivityTimeOutStrategy

          James Nord added a comment -

          NoActivityTimeOutStrategy.onWrite() calls BuildTimeoutWrapper.rescheduleIfNeeded() which will in this case cause a rescheduling.

          James Nord added a comment - NoActivityTimeOutStrategy.onWrite() calls BuildTimeoutWrapper.rescheduleIfNeeded() which will in this case cause a rescheduling.

          Code changed in jenkins
          User: James Nord
          Path:
          src/main/java/hudson/plugins/build_timeout/BuildTimeoutWrapper.java
          http://jenkins-ci.org/commit/build-timeout-plugin/ee18187343060a92a931e749815dd80abc1752d3
          Log:
          [FIXED JENKINS-31627] canceld TimerTasks should be purged.

          The TimerTask could be way off into the future as it is user input that
          decides when this is run (and or jobs running multiple days the inactivity
          could be 1 day). Without purging the Timer the TimerTasks stay into the
          queue until such time that they are the next task to run - at which time
          they are removed. But with all other triggers in a system (polling every
          minute etc) added timers could stay for their maximum duration.

          For arguments sake say this is 1 day and you have a build that produces
          10000 lines of output every 10 hours and uses the NoActivity strategy.
          In this case for every call to write you will have a new TimerTask created
          that should trigger in 24hours time - it is easy to see these 10000
          TimerTasks are referenced from the Timer and as such will not be garbaged
          collected for a long while.
          If you have lots of these styles of jobs - the required heap to run this
          becomes massive.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: James Nord Path: src/main/java/hudson/plugins/build_timeout/BuildTimeoutWrapper.java http://jenkins-ci.org/commit/build-timeout-plugin/ee18187343060a92a931e749815dd80abc1752d3 Log: [FIXED JENKINS-31627] canceld TimerTasks should be purged. The TimerTask could be way off into the future as it is user input that decides when this is run (and or jobs running multiple days the inactivity could be 1 day). Without purging the Timer the TimerTasks stay into the queue until such time that they are the next task to run - at which time they are removed. But with all other triggers in a system (polling every minute etc) added timers could stay for their maximum duration. For arguments sake say this is 1 day and you have a build that produces 10000 lines of output every 10 hours and uses the NoActivity strategy. In this case for every call to write you will have a new TimerTask created that should trigger in 24hours time - it is easy to see these 10000 TimerTasks are referenced from the Timer and as such will not be garbaged collected for a long while. If you have lots of these styles of jobs - the required heap to run this becomes massive.

          Code changed in jenkins
          User: ikedam
          Path:
          src/main/java/hudson/plugins/build_timeout/BuildTimeoutWrapper.java
          http://jenkins-ci.org/commit/build-timeout-plugin/5db020d28edf91db5a9fb87900100de701595abb
          Log:
          Merge pull request #47 from jtnord/JENKINS-31627

          [FIXED JENKINS-31627] canceled TimerTasks should be purged.

          Compare: https://github.com/jenkinsci/build-timeout-plugin/compare/16896012b4d4...5db020d28edf

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: ikedam Path: src/main/java/hudson/plugins/build_timeout/BuildTimeoutWrapper.java http://jenkins-ci.org/commit/build-timeout-plugin/5db020d28edf91db5a9fb87900100de701595abb Log: Merge pull request #47 from jtnord/ JENKINS-31627 [FIXED JENKINS-31627] canceled TimerTasks should be purged. Compare: https://github.com/jenkinsci/build-timeout-plugin/compare/16896012b4d4...5db020d28edf

          ikedam added a comment -

          Released 1.15.1 including the fix.
          It will be available in the update center in a day.

          ikedam added a comment - Released 1.15.1 including the fix. It will be available in the update center in a day.

            Unassigned Unassigned
            teilo James Nord
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: