Metaspace Leak in Pipeline Groovy and Script Security with Java 11

1 minute readKnowledge base

Issue

  • Jenkins restarts randomly due to memory issues

  • The metaspace on the controller instance has been slowly filling, though the java heap space usage stays relatively low.

Explanation

A bug in Java 11 JDK-8231454 is causing a leak of com.sun.beans.introspect.ClassInfo the metaspace whenever a the method java.beans.Introspector#getBeanInfo is invoked. In Jenkins, this is mainly used by the groovy engine through Pipeline: Groovy and Script Security for example.

The problem has been tackled in two directions:

Resolution

There are different solutions to solve this problem: upgrade Core/Plugins or upgrade java or both.

Solution 1: Upgrade Core and Plugins

Upgrade CloudBees CI to version 2.346.1.4 or later. This release contains the fix versions of Pipeline Groovy plugin and Script Security plugin.

Solution 2: Upgrade Java

Upgrade Java to version 11.0.16.1 or later.

due to another memory leak introduced in version 11.0.16, prefer version 11.0.16.1 or later rather than 11.0.16.