How to identify a thread leak issue?

The Jenkins service is running version 2.426.1 and is in production usage, utilized by multiple teams.
The service intermittently throws an error: ‘java.lang.OutOfMemoryError: unable to create native thread,’ causing it to stop working as expected. Upon restart, it functions normally for a few days (typically 4 to 5 days) before encountering the same error again.
Initial investigation reveals that the service crashes when it reaches its maximum allowable tasks (Java threads), which is 4915.
After collecting a thread dump and analyzing it with tools, the following stack trace output was obtained.

Before restart:

Count Line
4849 java.base@11.0.16/
4595 java.base@11.0.16/java.lang.Thread.sleep(Native Method)
4583$$Lambda$896/ Source)
229 java.base@11.0.16/jdk.internal.misc.Unsafe.park(Native Method)
160 java.base@11.0.16/java.util.concurrent.locks.LockSupport.parkNanos(

After restart:

Count Line
143 java.base@11.0.16/
99 java.base@11.0.16/jdk.internal.misc.Unsafe.park(Native Method)
76 java.base@11.0.16/java.util.concurrent.ThreadPoolExecutor$
76 java.base@11.0.16/java.util.concurrent.ThreadPoolExecutor.runWorker(
52 java.base@11.0.16/java.util.concurrent.locks.LockSupport.parkNanos(
47 java.base@11.0.16/java.util.concurrent.ThreadPoolExecutor.getTask(

It has been observed that the sleep thread (major number) is being terminated after the service restarts.

Assistance is needed to identify this thread leak issue and determine which build or job is causing it. Thank you in advance.

Just the fact that there are over 4500 threads for the class are a strong indicator. I think this class is used by the Subversion plugin
I’m not using this plugin so can’t help further. Might be worth opening a bug report for it including a stack trace so responsibles can analyze further.

There is a CloudBees article that notes a known issue with thread leaks in Java 11.0.16.

Java 11 releases a new version every 3 months. The current version is 11.0.23. I think that you should upgrade your Java version in case that resolves the issue.

Even if it does not resolve the issue, it is good to use a more recent patch release of Java 11.

1 Like

Thanks for the reply!
The bug report has been opened for the same.

Thank you for sharing the article. While it addresses memory leaks, our issue pertains to thread leaks. We’ll definitely consider updating Java. In the meantime, I’ve opened a bug report and we’ll see how it progresses.