TreeCache.iterator() throws NoSuchElementException after a parent node's last child is deleted
- Dominant language
- Java
- Stars
- 3.2k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
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.
Contributor guide
No contributing guide indexed for this repository
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.
Assessment
- Tech stack
- java
- Domain
- distributed-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100