HyukjinKwon opened a new pull request, #466:
URL: https://github.com/apache/spark-connect-rust/pull/466

   ### What changes were proposed in this pull request?
   
   [SPARK-61355](https://issues.apache.org/jira/browse/SPARK-61355): the Rust 
client retries a request that its connection closed before sending it, as 
PySpark does.
   
   - `RetryPolicy::can_retry` (`crates/spark-connect-core/src/retries.rs`) 
retries a `CANCELLED` whose source is hyper's canceled error.
     - hyper cancels a request only when the connection it was queued on closes 
before sending it ("connection closed", or "connection was not ready" for a 
connection that had already closed).
     - tonic reports hyper's canceled error as `CANCELLED` "operation was 
canceled", and keeps it as the status's source.
   - Still not retried: a `CANCELLED` that the server sent (no source), and 
tonic's timeout of a request (`TimeoutExpired`, also `CANCELLED`).
   - The check for a reset (`UNKNOWN` with a transport error as its source) and 
the new check share one walk over the status's sources.
   
   ### Why are the changes needed?
   
   After a connection reset, a request that was queued on the closing 
connection, but not sent yet, failed with `CANCELLED` "operation was canceled". 
The retry policy did not retry `CANCELLED`, so the error went out of the call. 
For example, `collect_reattaches_after_three_connection_resets` 
(`crates/spark-connect/tests/e2e_reattach_drop.rs`) failed at its `collect` in 
1 of 40 runs with 2 test threads:
   
   ```
   SparkError { kind: Connect, message: "[The operation was cancelled] 
operation was canceled", grpc_code: Some(1), ... }
   ```
   
   In PySpark 4.3.0, grpc-python fails a call whose connection breaks with 
`UNAVAILABLE`, which `DefaultPolicy` retries. Such a request was never sent, so 
it is safe to send it again.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. A request that a closing connection catches before sending it is now 
retried. Before, it failed with `CANCELLED` "operation was canceled".
   
   ### How was this patch tested?
   
   - Rust (`retries.rs`):
     - `test_can_retry_a_request_its_connection_closed_before_sending`: a 
request is queued on a hyper HTTP/2 client connection, which then closes before 
sending it. The request gets hyper's canceled error, tonic makes it 
`CANCELLED`, and the policy retries it. It fails without the change.
     - `test_cannot_retry_a_cancellation_the_server_sent_or_a_timeout`.
     - The test uses `hyper-util` as a new dev-dependency of 
`apache-spark-connect-core`. It was already in the dependency tree through 
tonic.
   - `e2e_reattach_drop` against a local Spark 4.3.0 server: 80 runs with 2 
test threads, with no failure (it failed 1 in 40 before).
   - Checks:
     - the lib tests of both crates (724 passed);
     - the build of all tests, also with `wasm-udf` and `datafusion,polars`, 
without warnings;
     - `cargo fmt --all --check`, and clippy with no diagnostics on the changed 
lines.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Opus 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]

Reply via email to