From e36041aadb789c406449198c62bc20329a9b34dd Mon Sep 17 00:00:00 2001
From: Vincent Massol <vincent@massol.net>
Date: Tue, 28 Nov 2017 18:36:34 +0100
Subject: [PATCH] XDOCKER-39: Slow XWiki startup under some conditions

---
 8/mysql-tomcat/tomcat/setenv.sh    | 10 +++++++---
 8/postgres-tomcat/tomcat/setenv.sh | 10 +++++++---
 9/mysql-tomcat/tomcat/setenv.sh    | 10 +++++++---
 9/postgres-tomcat/tomcat/setenv.sh | 10 +++++++---
 template/tomcat/setenv.sh          | 10 +++++++---
 5 files changed, 35 insertions(+), 15 deletions(-)

diff --git a/8/mysql-tomcat/tomcat/setenv.sh b/8/mysql-tomcat/tomcat/setenv.sh
index abcb1be..34ca6a2 100755
--- a/8/mysql-tomcat/tomcat/setenv.sh
+++ b/8/mysql-tomcat/tomcat/setenv.sh
@@ -1,3 +1,7 @@
-# By default, Tomcat does not allow the usage of encoded slash '%2F' and backslash '%5C' in URLs, as noted in http://tomcat.apache.org/security-6.html#Fixed_in_Apache_Tomcat_6.0.10.
-# This is why we're passing 2 system properties to allow for them as it's useful to be able to have '/' and '' in wiki pahe names.
-export CATALINA_OPTS="-Xmx1024m -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true -Dorg.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true"
+# We're making the following changes to the default:
+# * Adding more memory (default is 512MB which is not enough for XWiki)
+# * By default, Tomcat does not allow the usage of encoded slash '%2F' and backslash '%5C' in URLs, as noted in
+#   http://tomcat.apache.org/security-6.html#Fixed_in_Apache_Tomcat_6.0.10. We want to allow for them as it's useful to
+#   be able to have '/' and '' in wiki page names.
+# * On some system /dev/random is slow to init leading to a slow Tomcat and thus Xwiki startup.
+export CATALINA_OPTS="-Xmx1024m -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true -Dorg.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true -Dsecurerandom.source=file:/dev/urandom"
diff --git a/8/postgres-tomcat/tomcat/setenv.sh b/8/postgres-tomcat/tomcat/setenv.sh
index abcb1be..34ca6a2 100755
--- a/8/postgres-tomcat/tomcat/setenv.sh
+++ b/8/postgres-tomcat/tomcat/setenv.sh
@@ -1,3 +1,7 @@
-# By default, Tomcat does not allow the usage of encoded slash '%2F' and backslash '%5C' in URLs, as noted in http://tomcat.apache.org/security-6.html#Fixed_in_Apache_Tomcat_6.0.10.
-# This is why we're passing 2 system properties to allow for them as it's useful to be able to have '/' and '' in wiki pahe names.
-export CATALINA_OPTS="-Xmx1024m -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true -Dorg.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true"
+# We're making the following changes to the default:
+# * Adding more memory (default is 512MB which is not enough for XWiki)
+# * By default, Tomcat does not allow the usage of encoded slash '%2F' and backslash '%5C' in URLs, as noted in
+#   http://tomcat.apache.org/security-6.html#Fixed_in_Apache_Tomcat_6.0.10. We want to allow for them as it's useful to
+#   be able to have '/' and '' in wiki page names.
+# * On some system /dev/random is slow to init leading to a slow Tomcat and thus Xwiki startup.
+export CATALINA_OPTS="-Xmx1024m -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true -Dorg.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true -Dsecurerandom.source=file:/dev/urandom"
diff --git a/9/mysql-tomcat/tomcat/setenv.sh b/9/mysql-tomcat/tomcat/setenv.sh
index abcb1be..34ca6a2 100755
--- a/9/mysql-tomcat/tomcat/setenv.sh
+++ b/9/mysql-tomcat/tomcat/setenv.sh
@@ -1,3 +1,7 @@
-# By default, Tomcat does not allow the usage of encoded slash '%2F' and backslash '%5C' in URLs, as noted in http://tomcat.apache.org/security-6.html#Fixed_in_Apache_Tomcat_6.0.10.
-# This is why we're passing 2 system properties to allow for them as it's useful to be able to have '/' and '' in wiki pahe names.
-export CATALINA_OPTS="-Xmx1024m -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true -Dorg.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true"
+# We're making the following changes to the default:
+# * Adding more memory (default is 512MB which is not enough for XWiki)
+# * By default, Tomcat does not allow the usage of encoded slash '%2F' and backslash '%5C' in URLs, as noted in
+#   http://tomcat.apache.org/security-6.html#Fixed_in_Apache_Tomcat_6.0.10. We want to allow for them as it's useful to
+#   be able to have '/' and '' in wiki page names.
+# * On some system /dev/random is slow to init leading to a slow Tomcat and thus Xwiki startup.
+export CATALINA_OPTS="-Xmx1024m -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true -Dorg.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true -Dsecurerandom.source=file:/dev/urandom"
diff --git a/9/postgres-tomcat/tomcat/setenv.sh b/9/postgres-tomcat/tomcat/setenv.sh
index abcb1be..34ca6a2 100755
--- a/9/postgres-tomcat/tomcat/setenv.sh
+++ b/9/postgres-tomcat/tomcat/setenv.sh
@@ -1,3 +1,7 @@
-# By default, Tomcat does not allow the usage of encoded slash '%2F' and backslash '%5C' in URLs, as noted in http://tomcat.apache.org/security-6.html#Fixed_in_Apache_Tomcat_6.0.10.
-# This is why we're passing 2 system properties to allow for them as it's useful to be able to have '/' and '' in wiki pahe names.
-export CATALINA_OPTS="-Xmx1024m -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true -Dorg.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true"
+# We're making the following changes to the default:
+# * Adding more memory (default is 512MB which is not enough for XWiki)
+# * By default, Tomcat does not allow the usage of encoded slash '%2F' and backslash '%5C' in URLs, as noted in
+#   http://tomcat.apache.org/security-6.html#Fixed_in_Apache_Tomcat_6.0.10. We want to allow for them as it's useful to
+#   be able to have '/' and '' in wiki page names.
+# * On some system /dev/random is slow to init leading to a slow Tomcat and thus Xwiki startup.
+export CATALINA_OPTS="-Xmx1024m -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true -Dorg.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true -Dsecurerandom.source=file:/dev/urandom"
diff --git a/template/tomcat/setenv.sh b/template/tomcat/setenv.sh
index a28adfb..6b679ac 100755
--- a/template/tomcat/setenv.sh
+++ b/template/tomcat/setenv.sh
@@ -1,3 +1,7 @@
-# By default, Tomcat does not allow the usage of encoded slash '%2F' and backslash '%5C' in URLs, as noted in http://tomcat.apache.org/security-6.html#Fixed_in_Apache_Tomcat_6.0.10.
-# This is why we're passing 2 system properties to allow for them as it's useful to be able to have '/' and '\' in wiki pahe names.
-export CATALINA_OPTS="-Xmx1024m -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true -Dorg.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true"
+# We're making the following changes to the default:
+# * Adding more memory (default is 512MB which is not enough for XWiki)
+# * By default, Tomcat does not allow the usage of encoded slash '%2F' and backslash '%5C' in URLs, as noted in
+#   http://tomcat.apache.org/security-6.html#Fixed_in_Apache_Tomcat_6.0.10. We want to allow for them as it's useful to
+#   be able to have '/' and '\' in wiki page names.
+# * On some system /dev/random is slow to init leading to a slow Tomcat and thus Xwiki startup.
+export CATALINA_OPTS="-Xmx1024m -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true -Dorg.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true -Dsecurerandom.source=file:/dev/urandom"
-- 
GitLab