-
Notifications
You must be signed in to change notification settings - Fork 1.3k
GH-1277 SafeNotifyService threads leak in CuratorFrameWorkImpl #1278
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
Conversation
CURATOR-495 introduced a new runSafeService field in CuratorFrameworkImpl class, and this field is either initialized by an external ExecutorService via the builder, or it is created internally within the class. In the CuratorFrameworkImpl#close method though, this Executor is never closed, so the threads that are opened by the instances are lingering there until the VM is closed by default. Worse, if someone specifies a thread factory to the framework implementation via the builder that produces non-daemon threads, the VM never exits due to the unstopped single thread executor.
kezhuw
left a comment
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! I think we should add javadoc for runSafeService to point out that it is caller's responsibility to shutdown given executor.
| if (!isExternalRunSafeService) { | ||
| ((ExecutorService) runSafeService).shutdownNow(); | ||
| try { | ||
| ((ExecutorService) runSafeService).awaitTermination(maxCloseWaitMs, TimeUnit.MILLISECONDS); |
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.
We have two maxCloseWaitMs now. I am ok for it to be this for now, we can improve it in separated pr.
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.
Yes, you are right, I have changed the approach to ensure we have wait until maxCloseWaitMs for both executor in parallel. Should I add a test for that also what do you think?
|
@kezhuw Thank you for your review, I added to the JavaDoc of the Builder#runSafeService method, and changed the approach the close waits for these executors to be closed. |
|
Hi, is there any plan for merging this? |
|
Merged. Thank you all for contribution! |
CURATOR-495 introduced a new runSafeService field in CuratorFrameworkImpl class, and this field is either initialized by an external ExecutorService via the builder, or it is created internally within the class.
In the CuratorFrameworkImpl#close method though, this Executor is never closed, so the threads that are opened by the instances are lingering there until the VM is closed by default. Worse, if someone specifies a thread factory to the framework implementation via the builder that produces non-daemon threads, the VM never exits due to the unstopped single thread executor.