TreeCache.iterator() throws NoSuchElementException after a parent node's last child is deleted

Open
#1,302 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
java

Research direction

Start by reproducing the failure through TreeCache.iterator(), including the case where the cache root or a nested node loses its last child; also check the CuratorCache.stream() fallback described in the issue. Inspect how iteration handles a non-null empty children map, and consider the issue done when remaining live nodes can be traversed without NoSuchElementException.

Written by the indexing model from the issue text.

Description

Hi folks,

We hit a bug in the latest version of Curator's TreeCache::iterator implementation. I will describe the bug here and submit a PR to fix it.

If a user starts a TreeCache on a parent path that has children, and later every child of some cached node is deleted, TreeCache.iterator() throws NoSuchElementException instead of walking the remaining live nodes. That includes the cache root having all of its children deleted, and also a nested node having all of its children deleted.

A parent that never had children is OK (its children map stays null). The bug only appears after a node had children and then lost the last one. TreeCache keeps a non-null empty children map in that case, and the iterator tries to descend into it. Callers then cannot iterate the remaining live nodes until a new child is added or the cache is recreated.

Even though TreeCache itself is deprecated, this issue matters because CuratorCache falls back to TreeCache on a ZooKeeper version that does not support persistent watches. We hit this issue when using CuratorCache::stream on ZooKeeper 3.5.9.

Dominant language
Java
Stars
3.2k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/curator

All issues in apache/curator

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.