This is an automated email from the ASF dual-hosted git repository.
remm pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push:
new b123b0e56d Initialize Random during server initialization
b123b0e56d is described below
commit b123b0e56daa8fea1fffa0ed2f4580a973244cac
Author: remm <[email protected]>
AuthorDate: Thu Apr 6 16:11:09 2023 +0200
Initialize Random during server initialization
BZ66554, causing possible thread creation by the JVM using the context
of the webapp.
---
.../core/JreMemoryLeakPreventionListener.java | 24 ++++++++++++++++++++++
webapps/docs/changelog.xml | 5 +++++
webapps/docs/config/listeners.xml | 10 +++++++++
3 files changed, 39 insertions(+)
diff --git a/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java
b/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java
index a2d6b57ea0..a7cf157d06 100644
--- a/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java
+++ b/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java
@@ -20,6 +20,7 @@ import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URLConnection;
+import java.security.SecureRandom;
import java.sql.DriverManager;
import java.util.StringTokenizer;
import java.util.concurrent.ForkJoinPool;
@@ -241,6 +242,20 @@ public class JreMemoryLeakPreventionListener implements
LifecycleListener {
this.classesToInitialize = classesToInitialize;
}
+ /**
+ * Initialize JVM seed generator. On some platforms, the JVM will create a
thread for this task, which can get
+ * associated with a web application depending on the timing.
+ */
+ private boolean initSeedGenerator = false;
+
+ public boolean getInitSeedGenerator() {
+ return this.initSeedGenerator;
+ }
+
+ public void setInitSeedGenerator(boolean initSeedGenerator) {
+ this.initSeedGenerator = initSeedGenerator;
+ }
+
@Override
public void lifecycleEvent(LifecycleEvent event) {
@@ -450,6 +465,15 @@ public class JreMemoryLeakPreventionListener implements
LifecycleListener {
}
}
+ /*
+ * Initialize the SeedGenerator of the JVM, as some platforms
use
+ * a thread which could end up being associated with a webapp
rather
+ * than the container.
+ */
+ if (initSeedGenerator) {
+ SecureRandom.getSeed(1);
+ }
+
if (classesToInitialize != null) {
StringTokenizer strTok = new
StringTokenizer(classesToInitialize, ", \r\n\t");
while (strTok.hasMoreTokens()) {
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index a9e4b9b2ac..cac423a1ef 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -165,6 +165,11 @@
<bug>66543</bug>: Give
<code>StandardContext#fireRequestDestroyEvent</code>
its own log message. (fschumacher)
</fix>
+ <fix>
+ <bug>66554</bug>: Initialize Random during server initialization to
+ avoid possible JVM thread creation in the webapp context on some
+ platforms. (remm)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
diff --git a/webapps/docs/config/listeners.xml
b/webapps/docs/config/listeners.xml
index 1842406599..328130553b 100644
--- a/webapps/docs/config/listeners.xml
+++ b/webapps/docs/config/listeners.xml
@@ -272,6 +272,16 @@
been fixed for Java 9 onwards.</p>
</attribute>
+ <attribute name="initSeedGenerator" required="false">
+ <p>The first use of <code>SeedGenerator</code>, an internal class of
+ the default security spi implementation, might create a thread on some
+ platforms. Depending on the timing of the first use of a secure random
+ this thread might become associated with a webapp classloader, causing
+ a memory leak. Setting this to <code>true</code> will initialize the
+ seed. The default is <code>false</code> to avoid consuming random if
+ not needed.</p>
+ </attribute>
+
<attribute name="ldapPoolProtection" required="false">
<p>Enables protection so that the PoolCleaner thread started by
<code>com.sun.jndi.ldap.LdapPoolManager</code> does not result in a
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]