Closed ResoluteError closed 5 months ago
We can't do much in case of JVM fatal exceptions. There was at some point the logging handler added, that's why you see these logs. However, please refer to Simon's response and related discussions in that issue to understand more. Long story short, we can't handle Error
s like Exception
s and propagate them via Reactor's mechanisms. You have to resort to traditional JVM control structures if you want to catch any Error
. That is not recommended though and you should allow your JVM to exit as there might be no more memory left to even try to do any cleanup. External control is applicable - e.g. sizing your heap properly, responding to health checks (e.g. using Spring Boot Actuator's endpoint) and restarting the JVM using your orchestrator of choice (e.g. Kubernetes) if there's no timely response to the health checks.
Thanks for the explanation and immediate response - totally makes sense. Indeed using JVM controls via -XX:+ExitOnOutOfMemoryError
works fine when encountering actual OOM errors. Much appreciated. :)
In our current project, we have a reactive chain that consumes service bus message. When encountering a fatal exception (e.g. an OutOfMemory exception) within the chain, we need to gracefully shut down and restart the service. However, there seems to be no way of handling fatal exceptions. Other issues have referenced the
onErrorDropped
hook, but also does not seem to have the intended effect.When encountering a fatal exception, the service currently just hangs and the chain no longer processes any SerivceBus messages.
Expected Behavior
There should be a way to catch fatal exceptions for graceful service termination.
Actual Behavior
Fatal exceptions seem to evade all forms of error handling.
Steps to Reproduce
Returns logs:
Possible Solution
Your Environment
As a side note, we are using the Spring
@EventListener(ApplicationReadyEvent.class)
lifecycle annotation to subscribe to the service bus. If there is a better way that would automatically propagate these errors and close the spring context & shut down the application without manual error handling, I'm happy for any suggestions.I previously tried asking via StackOverflow but with no success.
Thank you for your support!