HyukjinKwon opened a new pull request, #908:
URL: https://github.com/apache/spark-connect-rust/pull/908
### What changes were proposed in this pull request?
The Rust client decoded the responses of the server at any depth: prost's
`no-recursion-limit` feature, which the client's own deep plans need, is
unified across the workspace. So a very deep response overflowed the stack and
ended the process, and a response deeper than 100 nested messages decoded where
PySpark raises an error.
- **The limit of a response:**
- Each response of the client is scanned first, without recursion, over a
table of the message-typed fields of the protos that `build.rs` generates:
`depth.rs` of the proto crate.
- It must hold at most 100 levels of nested messages, counted as upb and
prost count them (messages, map entries and groups), or 65535 once upb's
`SetAllowOversizeProtos(True)` is called, as the drop-in's protobuf runtime
follows it, with a bound of 1024 levels of known messages.
- A deeper response fails as PySpark's: the `SparkConnectGrpcException` of
`INTERNAL` "Exception deserializing response!", of grpcio's text of the call.
The Rust API gives prost's error of the limit, as the 4.3.0 Rust client did.
- `ClientCodec` scans only the client's responses: the generated server
bindings, which share it, decode their requests as before.
- The raw-bytes paths of the client use `ClientBytesCodec`, and the
decodes of status details are guarded.
- **No crash at any depth:**
- prost decodes a scanned response on a stack grown for its depth.
- The conversions of deep schemas, observed metrics and types grow the
stack per level. So do their `json()`, `repr()`, `==` and copies, and the
`Clone` of the core's `DataType`.
- Deep JSON values are dropped without recursion.
- **Threads of small stacks:** the waits of the calls and the conversions
run on a grown stack below a red zone, so calls on threads of 64 KiB and more
work, as PySpark's do.
- `with_udt_sql_types` copies nothing until a field is filled. It
deep-cloned the fields of every level, so deep UDT schemas are much faster.
- A new CI step runs the proto crate's tests on their own, of prost's limit.
### Why are the changes needed?
To fix the crash on deep responses and on threads of small stacks, and to
close the difference of the depth of the responses from PySpark (the
known-differences review).
### Does this PR introduce _any_ user-facing change?
Yes: a response deeper than 100 nested messages fails as in PySpark, and
nothing crashes at any depth or on small thread stacks. What remains is
documented in `docs/compatibility.md` and `dev/parity/known-differences.md`:
- responses of 1025 to 65535 levels with `SetAllowOversizeProtos(True)`;
- the pure-Python implementation's counting of unknown groups;
- Arrow batches of 61 to 63 nested structs, which arrow-rs refuses (tracked).
`ClientCodec` requires `prost::Name` of its decoded type: see the 4.4 Rust
migration notes.
### How was this patch tested?
- New tests in the proto crate (the boundary, map entries, unknown fields
and groups, malformed input, 10^6 levels on a 128 KiB thread, and a
differential fuzz against prost),
`crates/spark-connect-core/tests/response_depth.rs`,
`crates/spark-connect-server/tests/request_depth.rs` and
`python/tests/test_dropin_offline.py`, which fail without the change.
- Four rounds of an independent review. It compared the drop-in with PySpark
4.3.0 across 16 kinds of calls at depths 99 to 10^5, with and without oversize,
against a fake server and a live server: a struct column nested 31 levels
reads, 32 fails, in both. It also covered:
- a differential fuzz of 48,000 cases against prost and upb, and the table
against upb's descriptors;
- threads of 64 KiB to 1 MiB;
- the performance of wide and deep schemas.
Every finding was fixed or documented.
- The core tests (release and debug), wasm, clippy, rustdoc, the stubs, the
native server's crates and inventory, the offline suite in sorted order and
under coverage, and the live e2e with and without protobuf.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code
This pull request and its description were written by Isaac.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]