-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Using shutdown hook to close the LoggingSystem stops it before the spring application context when SIGHUP or Ctrl-C #4681
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I can't think a particularly easy way to fix this. Perhaps we can block for a short amount of time to see if |
See also #4651. The logging system is now only cleaned up when a root context is closed. This may make clean up a more viable option for cleaning up your custom logging system without resorting to a shutdown hook. |
There doesn't seem to be many options that we can implement to solve this in a generic way. Perhaps one thing that you could do for your code is add your own shutdown hook to close things in the correct order. You can use |
@brenuart please let us know if any of the suggested workarounds solve your issue. |
The last proposition is actually what we have done. Our listener will register its own shutdown hook upon reception of the Our hook also takes a reference to the running application context and attempts to close it before invoking the handler of the logging system. Since The reference to the running application context is obtained from the If the application fails to start, the hook is invoked only when the VM terminates - there is no application context anyway (it could not start). If interested, I could post a PR to illustrate what changes to actual code would be required. |
@brenuart Yes please for the PR with details. |
I think we're in danger of building a house of cards if we pursue the shutdown-hook-based approach. As I said in my comment above, the logging system is now only cleaned up as a result of the root context being closed. This is our preferred approach for shutting down the logging system and should be used in preference to a logging system shutdown hook. |
Since SpringBoot
1.3.0
, logging system implementations that need to be notified of the application close should register their own shutdown hook.Spring framework also registers its own shutdown hook to capture SIGUP/Ctrl-C events and close the application context.
Since the jvm is likely to invoke shutdown hooks in parallel, the logging system may be closed before (or during) the application context - hence loosing all log messages generated during the shutdown sequence.
See #4026 for more information.
The text was updated successfully, but these errors were encountered: