tdcmeehan opened a new pull request, #435: URL: https://github.com/apache/spark-connect-rust/pull/435
### What changes were proposed in this pull request? [SPARK-61261](https://issues.apache.org/jira/browse/SPARK-61261): when the connection drops in the middle of a result, reattach to the execution and keep reading, as PySpark does, instead of failing the query. - `RetryPolicy::can_retry` (`crates/spark-connect-core/src/retries.rs`) retries a status with code `UNKNOWN` when tonic built it from a transport error. A connection reset during a response reaches the client as `UNKNOWN`, with an `h2::Error` or `hyper::Error` in the status's source chain. grpc-python reports the same reset as `UNAVAILABLE`, which PySpark retries. A status the server sent has no source, so a server-sent `UNKNOWN` (for example an exception) stays non-retryable. - The reattach loop in `crates/spark-connect-core/src/client.rs` already retries the statuses that `can_retry` accepts, so no change is needed there. - `h2` and `hyper` become direct dependencies of `apache-spark-connect-core`, to name the transport error types. Both are already in the lock file through tonic. ### Why are the changes needed? With a connection reset once after about 2 MB of a result, `spark.range(3_000_000).collect()` through the Rust client fails after about 0.4 seconds with `[Unknown error] h2 protocol error: error reading a body from connection`. PySpark 4.3.0 reconnects, reattaches and returns all rows. The status that tonic reports for the reset is `UNKNOWN`, which the retry policy did not retry, so the reattach loop never ran. Matching on the status code alone would also retry server-sent `UNKNOWN` errors, so the check looks at the transport error that tonic keeps as the status's source. ### Does this PR introduce _any_ user-facing change? Yes. A query whose connection drops in the middle of its result is now resumed by reattaching, and returns every row, instead of failing with `[Unknown error] h2 protocol error`. Server-sent errors are unchanged. ### How was this patch tested? Repro against a local Spark 4.3.0 Connect server, through a TCP proxy that resets the client connection after about 2 MB of the response, for `spark.range(3_000_000).collect()`: - pyspark-client 4.3.0, 1 reset: 3000000 rows, sum 4499998500000, 9.8 s. 3 resets: 3000000 rows, sum 4499998500000, 8.0 s. - Rust client before this change, 1 reset: `SparkConnectGrpcException: [Unknown error] h2 protocol error: error reading a body from connection`, after 0.4 s. - Rust client with this change, 1 reset: 3000000 rows, sum 4499998500000, 6.4 s. 3 resets: 3000000 rows, sum 4499998500000, 5.6 s. Tests added: - `retries::tests::test_can_retry_a_connection_reset_during_a_response`: a local HTTP/2 server cuts a response off in the middle of a gRPC message and resets the connection. The status is `UNKNOWN` from tonic, and `can_retry` accepts it. It fails without the change. - `retries::tests::test_cannot_retry_an_unknown_the_server_sent`: the same server ends the response with a status the server sent, `UNKNOWN` "boom". `can_retry` rejects it. This passes with and without the change, and guards the server-sent case. - `crates/spark-connect/tests/e2e_reattach_drop.rs`: a TCP proxy in front of the server (gated on `SPARK_REMOTE`) resets the connection once and three times; each run collects every row and checks the count and the sum of ids. Both fail without the change with the error above, and pass with it. Checks: `cargo test -p apache-spark-connect --release --lib` 528 passed; `--no-run` builds, with and without `wasm-udf`; `cargo fmt --all --check` clean; `cargo test -p apache-spark-connect-core --release` with `SPARK_REMOTE` set, all suites pass (lib 152 passed, including the 2 new tests); clippy reports no diagnostic on the changed lines; offline Python suites `tests/test_dropin_offline.py tests/test_ml_offline.py tests/test_arrow_handoff.py` 2927 passed, 8 skipped; live drop-in, Arrow and ML suites against a local Spark 4.3.0 server, 236 passed, 1 skipped. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Opus 5.5 and Claude Haiku 5.5 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]
