Skip to content
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

ZOOKEEPER-4309 QuorumCnxManager's ListenerHandler thread leak #1705

Closed
wants to merge 1 commit into from

Conversation

franz1981
Copy link
Contributor

@franz1981
Copy link
Contributor Author

franz1981 commented May 31, 2021

Writing a test for this means both mocking or adding more state into Listener class: let me know if it's needed. It just looks like a simple executor leak.

@kyangcmXF
Copy link

hi guy,
I replied to you in apache link.

@franz1981
Copy link
Contributor Author

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM

I left a suggestion, if you want to take it into consideration please @franz1981

otherwise I am happy with merging the patch as it is

@@ -957,8 +957,13 @@ public void run() {
new ListenerHandler(address, self.shouldUsePortUnification(), self.isSslQuorum(), latch))
.collect(Collectors.toList());

ExecutorService executor = Executors.newFixedThreadPool(addresses.size());
listenerHandlers.forEach(executor::submit);
final ExecutorService executor = Executors.newFixedThreadPool(addresses.size());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about creating a shared ExecutorService, as a field in this class ?
this way it will be clearer the life cycle of this pool.

also, probably it would be worth to not use a pool in case of a list of addresses of size 1, but this may be a follow up work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about creating a shared ExecutorService, as a field in this class ?

I was thinking the same, but then I've found https://github.com/franz1981/zookeeper/blob/b4f9aab099880ba8ef08eaff697debe6cdeae057/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/Leader.java#L456-L468 and see that other parts in the ZK code just do it right without any hook to check for Thread "liveness".

I believe having a shared pluggable executor service could worth for embedded use cases, where people would like to keep control on thread creation, instead.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about creating a shared ExecutorService, as a field in this class ?
this way it will be clearer the life cycle of this pool.

also, probably it would be worth to not use a pool in case of a list of addresses of size 1, but this may be a follow up work

we can use a global shared thread pool just as what we do in spring. For example we use @component annotation to register a pool.
however there's a question we need figure it out if the pool is io computed pool or a cpu computed pool.
I think that is io computed pool because we use to accept ticket there.
@eolivelli

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's stick with this patch.
we can improve things later

@franz1981
Copy link
Contributor Author

@eolivelli Any news on this?

@eolivelli
Copy link
Contributor

@franz1981
in order to commit the patch we need at least another reviewer

tagging @anmolnar @hanm @nkalmar @symat @ztzg

@franz1981
Copy link
Contributor Author

let's stick with this patch.
we can improve things later
@eolivelli

I'm a OSS lover (beside my actual job), so would be happy to help on this :)

@ztzg
Copy link
Contributor

ztzg commented Jun 7, 2021

Planning to look into this on Wednesday (unless somebody beats me to it, of course).

Copy link
Contributor

@ztzg ztzg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I agree that getting rid of the leak is a good first step.

@franz1981
Copy link
Contributor Author

@hanm @ztzg @eolivelli happy that the fix is sound: as said probably worth considering some centralized way to create thread(s)/thread pools for a follow-up work on this

@eolivelli eolivelli closed this in 7855045 Jun 14, 2021
eolivelli pushed a commit that referenced this pull request Jun 14, 2021
https://issues.apache.org/jira/browse/ZOOKEEPER-4309

Author: franz1981 <nigro.fra@gmail.com>

Reviewers: Enrico Olivelli <eolivelli@apache.org>, Michael Han <hanm@apache.org>, Damien Diederen <ddiederen@apache.org>

Closes #1705 from franz1981/ZOOKEEPER-4309

(cherry picked from commit 7855045)
Signed-off-by: Enrico Olivelli <eolivelli@apache.org>
@eolivelli
Copy link
Contributor

committed to master branch and to branch-3.7.
the fix will be available on ZK 3.8.0 and 3.7.1

thank you !

anuragmadnawat1 pushed a commit to anuragmadnawat1/zookeeper that referenced this pull request Nov 2, 2022
https://issues.apache.org/jira/browse/ZOOKEEPER-4309

Author: franz1981 <nigro.fra@gmail.com>

Reviewers: Enrico Olivelli <eolivelli@apache.org>, Michael Han <hanm@apache.org>, Damien Diederen <ddiederen@apache.org>

Closes apache#1705 from franz1981/ZOOKEEPER-4309
anuragmadnawat1 added a commit to anuragmadnawat1/zookeeper that referenced this pull request Nov 2, 2022
https://issues.apache.org/jira/browse/ZOOKEEPER-4309

Author: franz1981 <nigro.fra@gmail.com>

Reviewers: Enrico Olivelli <eolivelli@apache.org>, Michael Han <hanm@apache.org>, Damien Diederen <ddiederen@apache.org>

Closes apache#1705 from franz1981/ZOOKEEPER-4309

Co-authored-by: franz1981 <nigro.fra@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants