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

CURATOR-710: Fix leaking watch in EnsembleTracker #508

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kezhuw
Copy link
Member

@kezhuw kezhuw commented Oct 16, 2024

CURATOR-667(#474) fixes asynchronous event path for getConfig to
"/zookeeper/config" by using CuratorFramework::usingNamespace(null) to
fetch data.

It causes watcher not registering to possible WatcherRemovalManager,
so leaking in WatcherRemoveCuratorFramework::removeWatchers.

@kezhuw kezhuw force-pushed the CURATOR-710-fix-EnsembleTracker-leak-watch branch from a6319f0 to b74abb0 Compare October 28, 2024 08:10
CURATOR-667(apache#474) fixes asynchronous event path for `getConfig` to
"/zookeeper/config" by using `CuratorFramework::usingNamespace(null)` to
fetch data.

It causes watcher not registering to possible `WatcherRemovalManager`,
so leaking in `WatcherRemoveCuratorFramework::removeWatchers`.
@kezhuw kezhuw force-pushed the CURATOR-710-fix-EnsembleTracker-leak-watch branch from b74abb0 to cd03c72 Compare October 28, 2024 08:14
Comment on lines +66 to +69
Watching setWatcherRemovalManager(WatcherRemovalManager watcherRemovalManager) {
this.watcherRemovalManager = watcherRemovalManager;
return this;
}
Copy link
Member

Choose a reason for hiding this comment

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

It seems the watcherRemovalManager already set in the constructor by this.watcherRemovalManager = client.getWatcherRemovalManager();?

Copy link
Member

Choose a reason for hiding this comment

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

Or otherwise we can merge this setter into the constructor as a parameter.

if (client.getWatcherRemovalManager() != null) {
client.getWatcherRemovalManager().add(namespaceWatcher);
}
if (doCommit && namespaceWatcher != null && watcherRemovalManager != null) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you elaborate a bit when watcherRemovalManager can be different from client.getWatcherRemovalManager().

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with the question: we can save some memory by not having the field. The performance impact is negligible

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. Given a fresh new CuratorFrameworkImpl, say framework0.
  2. Let's assume framework1 = framework0.newWatcherRemoveCuratorFramework(). framework1.getWatcherRemovalManager will be the WatcherRemovalManager.
  3. Let's assume framework2 = frame1.usingNamespace(null). framework2 will loss WatcherRemovalManager from above.
  4. framework1.removeWatchers will not drop watchers from new Watching(framework2, ...).

Step.2 is what exactly EnsembleTracker does.

EnsembleTracker(CuratorFramework client, EnsembleProvider ensembleProvider) {
this.client = client.newWatcherRemoveCuratorFramework();
this.ensembleProvider = ensembleProvider;
}

Step.3 is what exactly GetConfigBuilderImpl(CURATOR-667(#474)) does currently.

public GetConfigBuilderImpl(CuratorFrameworkImpl client) {
this.client = (CuratorFrameworkImpl) client.usingNamespace(null);
backgrounding = new Backgrounding();
watching = new Watching(this.client);
}

Step.4 is where this bug emerges.

public void close() {
if (state.compareAndSet(State.STARTED, State.CLOSED)) {
client.removeWatchers();
client.getConnectionStateListenable().removeListener(connectionStateListener);
}
}

I have pushed a fixup commit 6b78a3b with comments to doc this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants