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
Avoid addShutdownHook to JVM during its shutdown #5524
Avoid addShutdownHook to JVM during its shutdown #5524
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @thachlp! 👍
Runtime.getRuntime().addShutdownHook(new Thread(() -> { | ||
if (!shutdownHookDisabled) { | ||
ClientFactory.closeDefault(); | ||
if (!shutdownHookDisabled) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't do anything because the static initialization block is always called before static method(e.g. disableShutdownHook0()
here).
Let's just catch the exception instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for explain, updated 🙇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't do anything because the static initialization block is always called before static method(e.g. disableShutdownHook0() here).
Question) Would users still want to disable automatic shutdown to a later timing of their choosing by calling ClientFactory#disableShutdownHook
? or is #1472 not an issue anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some minor commits - let me know if any of the changes doesn't make sense. Thanks @thachlp ! 🙇 👍 🙇
Motivation:
Currently a JVM shutdown hook is added when DefaultClientFactory is used for the first time (code). It is possible that a JVM shutdown hook is being added after the JVM has started its shutdown and results in an exception below:
Modifications:
java.lang.IllegalStateException
Result:
addShutdownHook
to JVM during its shutdown #5494