[
https://issues.apache.org/jira/browse/OAK-12558?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Rishabh Daim updated OAK-12558:
-------------------------------
Description:
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]
h3. Local implementation and verification
The fix is implemented locally on issue/OAK-12558, based on trunk
29366bbaf7373bd7a76df8d89ee1f9f9ca1e0c95. All nine public chaining overloads
use one package-private concatenation engine. It walks nested child states
using an explicit traversal path, checking the active leaf once per hasNext()
and retaining child iterator state rather than draining pending inputs.
Bookkeeping is linear in nesting depth rather than exponential, and traversal
does not recurse through Oak concatenation iterators.
No callers or public API signatures are changed. The implementation retains
lazy iterable input opening, existing eager validation/snapshot behavior of
iterator overloads, ordering, repeatable iterable views, null element handling,
and supported removal. The implementation is enabled by default; the startup
property {{-DFT_OAK-12558=false}} restores the previous engine, following the
repository toggle guidance.
Verification on Java 17:
* A deterministic 20-level regression failed before the fix: expected 1 leaf
poll, observed 1,048,576.
* A 128-level accumulating-chain regression timed out after 10 seconds before
the fix. With the fix it validates all nine overloads and all 129 values; the
local run completed in 0.005 seconds. The unfixed recurrence would require
approximately 2^128 leaf polls before the first value.
* 100,000 nested iterable/iterator chains complete without recursive stack
growth.
* 100,000 flat inputs retain linear leaf polling.
* Compatibility controls cover already-polled and partially consumed children,
continued child use after parent polling, eager null validation, lazy and
infinite input sources, repeated iteration, null values, exhaustion and
supported/unsupported removal.
* {{mvn -o -B -pl oak-commons clean verify apache-rat:check}}: 715 tests, zero
failures/errors/skips. Includes 13 new tests.
* Coverage checks passed; new iterator has 100% line and 95% branch coverage in
the default-mode suite.
* Bundle baseline: zero errors and warnings. Apache RAT: zero unapproved or
unknown files.
* Existing IterableUtilsTest and IteratorUtilsTest also pass with the feature
disabled: 252 tests, zero failures/errors/skips.
was:
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]
> 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
> Priority: Major
>
> 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]
> h3. Local implementation and verification
> The fix is implemented locally on issue/OAK-12558, based on trunk
> 29366bbaf7373bd7a76df8d89ee1f9f9ca1e0c95. All nine public chaining overloads
> use one package-private concatenation engine. It walks nested child states
> using an explicit traversal path, checking the active leaf once per hasNext()
> and retaining child iterator state rather than draining pending inputs.
> Bookkeeping is linear in nesting depth rather than exponential, and traversal
> does not recurse through Oak concatenation iterators.
> No callers or public API signatures are changed. The implementation retains
> lazy iterable input opening, existing eager validation/snapshot behavior of
> iterator overloads, ordering, repeatable iterable views, null element
> handling, and supported removal. The implementation is enabled by default;
> the startup property {{-DFT_OAK-12558=false}} restores the previous engine,
> following the repository toggle guidance.
> Verification on Java 17:
> * A deterministic 20-level regression failed before the fix: expected 1 leaf
> poll, observed 1,048,576.
> * A 128-level accumulating-chain regression timed out after 10 seconds before
> the fix. With the fix it validates all nine overloads and all 129 values; the
> local run completed in 0.005 seconds. The unfixed recurrence would require
> approximately 2^128 leaf polls before the first value.
> * 100,000 nested iterable/iterator chains complete without recursive stack
> growth.
> * 100,000 flat inputs retain linear leaf polling.
> * Compatibility controls cover already-polled and partially consumed
> children, continued child use after parent polling, eager null validation,
> lazy and infinite input sources, repeated iteration, null values, exhaustion
> and supported/unsupported removal.
> * {{mvn -o -B -pl oak-commons clean verify apache-rat:check}}: 715 tests,
> zero failures/errors/skips. Includes 13 new tests.
> * Coverage checks passed; new iterator has 100% line and 95% branch coverage
> in the default-mode suite.
> * Bundle baseline: zero errors and warnings. Apache RAT: zero unapproved or
> unknown files.
> * Existing IterableUtilsTest and IteratorUtilsTest also pass with the feature
> disabled: 252 tests, zero failures/errors/skips.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)