Extend Startup Failure Analyzers for lack of entropy
Motivational Scenario When somebody is starting numerous spring boot applications (in Docker container) on a host (e.g. Dockerhost) without conducting many operations (e.g.. just starting the operation for testing purposes), the host may run out of entropy and the startup seems to be stuck. See [1] for example.
Desired Feature Here it would be great, if spring boot would conduct a failure analysis, similar to the PortInUse one [2], and report the lack of entropy and suggest solutions, like installing haveged [3] or the usage of "-Djava.security.egd=file:/dev/./urandom".
[1] http://stackoverflow.com/questions/27612209/spring-boot-application-wont-boot-at-startup-inside-docker [2] spring-boot/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/PortInUseFailureAnalyzer.java [3] http://www.issihosts.com/haveged/
It's a nice idea, but I'm not sure that it's possible. Unfortunately, there's no exception to indicate that there's a lack of entropy. All that happens is that a call to SecureRandom doesn't return in a timely manner. I can't think of a simple way to detect that that is what's happened. Perhaps you had an idea?
One (rather hacky) approach would be to use sth like Spring retry [1], wait for some time and issue the exception as a "compensation" measure
[1] https://github.com/spring-projects/spring-retry
Unfortunately, Spring Retry won't help. The code that's involved is pure Tomcat so there's no opportunity for anything Spring-related to get involved. There's also no (safe) way to stop the thread that's stuck due to lack of entropy. I really don't think there's anything simple that we can do about this in Spring Boot.
The problem appears to be specific to Tomcat – as far as I know Jetty and Undertow are not affected – so perhaps you could raise a Tomcat issue?
This issue most definitely also exists with Jetty and Undertow.
@Starefossen As far as I know, neither Jetty nor Undertow uses SecureRandom during startup. I believe its use is deferred until the first HTTP session is created. That's the case now too with Tomcat as we've customised its session ID generation. If you have evidence to the contrary can you please share it and we'll take a look?