Skip to content

[fix][broker][branch-2.8] Fix watcher count on ZK increasing indefinitely#18234

Closed
coderzc wants to merge 1 commit intoapache:branch-2.8from
coderzc:fix_watcher_leak
Closed

[fix][broker][branch-2.8] Fix watcher count on ZK increasing indefinitely#18234
coderzc wants to merge 1 commit intoapache:branch-2.8from
coderzc:fix_watcher_leak

Conversation

@coderzc
Copy link
Member

@coderzc coderzc commented Oct 28, 2022

Motivation

I find some z-node only call exist and add watcher, but ExistsWatchRegistration still will be registered even though the z-node may never be created. this will lead to the watcher count on ZK increasing indefinitely.

    /** Handle the special case of exists watches - they add a watcher
     * even in the case where NONODE result code is returned.
     */
    class ExistsWatchRegistration extends WatchRegistration {

        public ExistsWatchRegistration(Watcher watcher, String clientPath) {
            super(watcher, clientPath);
        }

        @Override
        protected Map<String, Set<Watcher>> getWatches(int rc) {
            return rc == 0 ? watchManager.dataWatches : watchManager.existWatches;
        }

        @Override
        protected boolean shouldAddWatch(int rc) {
            return rc == 0 || rc == KeeperException.Code.NONODE.intValue();
        }

    }

Modifications

Remove watcher if exist return NONODE.
Remove unused method in ZkUtils.

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository:

@coderzc coderzc closed this Oct 28, 2022
@coderzc coderzc deleted the fix_watcher_leak branch October 28, 2022 04:25
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.

2 participants