fix(proto): prevent logical plan serialization stack overflow (#24124) - #31
Merged
Merged
Conversation
…#24124) - Closes apache#23823. `LogicalPlanNode::try_from_logical_plan` recursively serializes logical plans to protobuf. In debug builds, its large `match` compiled to a 202,304 B stack frame, so ten nested `SubqueryAlias` nodes over an `EmptyRelation` overflowed a 2 MiB thread stack. Each arm was isolated independently against the original dispatcher: | Independent frame effect | Arms | Examples | | --- | ---: | --- | | >=10 KiB reduction | 4 | TableScan: 34,608 B; Join: 11,392 B; Dml / RecursiveQuery: 10,320 B | | 5-8 KiB reduction | 17 | Projection, Filter, Aggregate, Repartition, Unnest, Copy | | 2-4 KiB reduction | 7 | Values, EmptyRelation, Union, Extension | | <=64 B effect | 9 | Several DDL/statement arms; Subquery adds 16 B | These effects are not additive: each change alters the compiler's layout of the same `match` frame. Isolating the 15 arms with the largest independent reductions still left a 58,560 B frame; isolating all 37 arms reduced it to 1,680 B. - Isolate every `try_from_logical_plan` match arm behind a debug-only non-inlined helper, preventing arm-local temporaries from inflating the recursive dispatcher frame. - Add the opt-in `datafusion-proto/recursive_protection` feature using the existing DataFusion recursion pattern. - Add child-process stack-safety regressions for the original 2 MiB-stack reproducer and feature-gated stack growth. With `recursive_protection`, the dispatcher frame measures 1,648 B. The helper is only forced out of line in debug builds. Yes. - `cargo fmt --all --check` - `cargo check -p datafusion-proto --all-features` - `cargo test -p datafusion-proto --lib` - Stack-safety regression: 100 nested aliases on a 2 MiB stack. - Feature-gated stack-growth regression: 2,000 nested aliases with `recursive_protection`. `datafusion-proto` gains an opt-in `recursive_protection` feature. Existing protobuf wire format, conversion behavior, and default features are unchanged.
Apply the same approach as applied for the encoding part.
askalt
force-pushed
the
askalt/fix-serialization-stack-overflow
branch
from
September 28, 2026 14:08
c2be1f7 to
6f9e921
Compare
Author
|
Upstream PR (the decode part fix): apache#25831 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.