Metaspace Leak Due to classes not being cleaned up

Article ID:360029574172
2 minute readKnowledge base

Issue

  • I have been seeing Jenkins restart randomly due to memory issues but it still seems to have a lot of heap space unused before the crash

  • The metaspace on the machine where my Jenkins instance is running has been slowly filling up and we are not sure why

Cause 1

SandboxResolvingClassLoader.parentClassCache could leak loaders: Whenever doing an import of classes using groovy scripts within plugins, there was the possibility to leak the class loader due to the cache holding the class reference

Resolution 1

SandboxResolvingClassLoader.parentClassCache could leak loaders: This issue was fixed in this PR and merged in to version 1.60 of the script security plugin.

This plugin version is included in the release 2.176.2.3. We encourage you to update to the newest version, alternatively you can manually download and install the plugin on your instance.

Cause 2

JENKINS-50223: Whenever a class was called within another class in a shared library, there was the possibility for it to take a very long time or never get removed from memory due to another caching issue

Resolution 2

JENKINS-50223: This issue was fixed in the 2.69 version of the Pipeline: Groovy plugin with this PR.

This plugin version is included in the release 2.176.2.3. We encourage you to update to the newest version, alternatively you can manually download and install the plugin on your instance.