Skip to content

Fix infinite RecursiveCursor out-of-band behavior - #4136

Merged
MMcM merged 2 commits into
FoundationDB:mainfrom
hatyo:bug-rcte
May 11, 2026
Merged

MMcM merged 2 commits into
FoundationDB:mainfrom
hatyo:bug-rcte

Conversation

@hatyo

@hatyo hatyo commented May 6, 2026 •

Copy link
Copy Markdown
Contributor

When recursionLoop() encountered an out-of-band stop, it built the continuation at depth - 1 (postorder) or depth (preorder before first emit), discarding the child cursor's scan progress. On resume, addChildNode would create a fresh node with a START continuation, causing the child cursor to re-scan from the beginning and hit the same limit indefinitely.

This fixes #4135.

@hatyo hatyo added the bug fix Change that fixes a bug label May 6, 2026
// Stop before child.
continuation = buildContinuation(depth);
}
final RecordCursorContinuation continuation = buildContinuation(depth + 1);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For preorder, won't this occasionally lose a node that had emitPending and hits the scan limit before the first child? The new test doesn't see this because its indexes are efficient enough that you always get a record each scan, until the end.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s correct. I verified this through a test that performs “inefficient” scans by disabling the secondary indexes and discovered that sometimes, that node is missing between the out-of-band and the continuation resumption. To address this, I modified the code by adding a conditional that reduces the depth of the saved continuation by one if we’re in preorder traversal and the node was in the emit-pending state so we don't miss it.

@MMcM
MMcM merged commit 62f9543 into FoundationDB:main May 11, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug fix Change that fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RecursiveCursor erroneous behavior on out-of-band stop during postorder traversal

2 participants