Reputation: 85266
I've encountered this issue twice recently, in Debian 9 as well as Ubuntu 16.04 LTS.
After a fresh install of the OS with just Tomcat 8 and openjdk 8 (no changes to the default config), after a few restarts the Tomcat server stops responding on port 8080.
The server is still listening on the port, but even a simple GET /
just hangs forever:
# netstat -an|grep 8080
tcp6 0 0 :::8080 :::* LISTEN
# wget http://127.0.0.1:8080/
--2017-11-03 13:19:52-- http://127.0.0.1:8080/
Connecting to 127.0.0.1:8080... connected.
HTTP request sent, awaiting response...
According to the thread dump Tomcat appears to be hanging on startup:
"localhost-startStop-1" #14 daemon prio=5 os_prio=0 tid=0x00000000018a1000 nid=0x68d8 runnable [0x00007f2badacd000]
java.lang.Thread.State: RUNNABLE
at java.io.FileInputStream.readBytes(Native Method)
at java.io.FileInputStream.read(FileInputStream.java:255)
at sun.security.provider.SeedGenerator$URLSeedGenerator.getSeedBytes(SeedGenerator.java:539)
at sun.security.provider.SeedGenerator.generateSeed(SeedGenerator.java:144)
at sun.security.provider.SecureRandom$SeederHolder.<clinit>(SecureRandom.java:203)
at sun.security.provider.SecureRandom.engineNextBytes(SecureRandom.java:221)
- locked <0x00000000f99155c0> (a sun.security.provider.SecureRandom)
at java.security.SecureRandom.nextBytes(SecureRandom.java:468)
at java.security.SecureRandom.next(SecureRandom.java:491)
at java.util.Random.nextInt(Random.java:329)
at org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom(SessionIdGeneratorBase.java:237)
at org.apache.catalina.util.SessionIdGeneratorBase.getRandomBytes(SessionIdGeneratorBase.java:174)
at org.apache.catalina.util.StandardSessionIdGenerator.generateSessionId(StandardSessionIdGenerator.java:34)
at org.apache.catalina.util.SessionIdGeneratorBase.generateSessionId(SessionIdGeneratorBase.java:167)
at org.apache.catalina.util.SessionIdGeneratorBase.startInternal(SessionIdGeneratorBase.java:256)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
- locked <0x00000000f9905808> (a org.apache.catalina.util.StandardSessionIdGenerator)
Why is this happening and how to fix it?
Upvotes: 2
Views: 581
Reputation: 85266
OpenJDK 8 on Debian-based distros comes with /dev/random
preconfigured as the source of entropy.
When there isn't enough entropy, /dev/random
will block.
Solution 1: (preferred)
Install haveged, it's a daemon that generates additional entropy.
Solution 2: (probably less secure)
Change /usr/lib/jvm/default-java/jre/lib/security/java.security
to use /dev/urandom
instead:
#securerandom.source=file:/dev/random
securerandom.source=file:/dev/./urandom
That will apply globally to all Java processes.
Alternatively, add -Djava.security.egd=file:/dev/./urandom
to JAVA_OPTS
in /etc/default/tomcat8
(will apply to Tomcat processes only).
Upvotes: 4