Rishabh Daim created OAK-12558:
----------------------------------

             Summary: Avoid exponential polling in nested oak-commons 
concatenation APIs
                 Key: OAK-12558
                 URL: https://issues.apache.org/jira/browse/OAK-12558
             Project: Jackrabbit Oak
          Issue Type: Bug
            Reporter: Rishabh Daim
            Assignee: Rishabh Daim


h3. Problem
OAK-11451 replaced Guava Iterables.concat with Apache Commons 
Collections-backed chaining. Nested concatenations can now perform 
exponentially many hasNext() calls because LazyIteratorChain checks the current 
iterator in both updateCurrentIterator() and hasNext(), without unpacking 
nested chains.

OAK-12532 fixes one affected caller in Mongo revision GC by collecting query 
iterables and chaining once. The utility APIs remain vulnerable, including the 
Iterable<Iterable<E>> overload and the IteratorUtils helpers changed by 
OAK-12410.

A deterministic reproduction with one counting leaf and 20 nested 
concatenations makes 1,048,576 leaf hasNext() calls for one successful outer 
hasNext(). The Guava 33.4.0 implementation used before OAK-11451 makes one leaf 
call by traversing nested concatenations iteratively.

h3. Caller audit
Latest trunk was checked at 29366bbaf7373bd7a76df8d89ee1f9f9ca1e0c95: 49 
production-source call sites and 46 test-source call sites. MapRecord.getKeys() 
and getEntries() also recursively compose chains. Their trie depth is capped at 
seven, so their amplification is bounded; no second unbounded accumulating 
production caller was found beyond the GC case already fixed by OAK-12532.

h3. Required fix
* Fix concatenation centrally in oak-commons, covering all five 
IterableUtils.chainedIterable overloads and all four 
IteratorUtils.chainedIterator overloads.
* Avoid exponential polling and recursive iterator-call stack growth without 
requiring caller-side changes or a Guava dependency.
* Preserve iteration order, lazy input opening, repeatable Iterable behavior, 
null handling, supported remove behavior, and already-polled or partially 
consumed child iterators (including the OAK-12410 regression).
* Add deterministic counting regressions and deep-nesting tests, plus 
compatibility controls.
* Run the full oak-commons test suite, coverage and bundle baseline 
verification.

h3. References
* [OAK-12532|https://issues.apache.org/jira/browse/OAK-12532]
* [OAK-11451|https://issues.apache.org/jira/browse/OAK-11451]
* [OAK-12410|https://issues.apache.org/jira/browse/OAK-12410]
* [COLLECTIONS-722|https://issues.apache.org/jira/browse/COLLECTIONS-722]
* [COLLECTIONS-900|https://issues.apache.org/jira/browse/COLLECTIONS-900]




--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to