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

   ### What changes were proposed in this pull request?
   
   [SPARK-61198](https://issues.apache.org/jira/browse/SPARK-61198): PySpark 
retries an RPC in `for attempt in self._retrying()`, and each attempt goes 
through `SparkConnectClient._stub`, which raises `NO_ACTIVE_SESSION` once the 
client is closed. So when a session is stopped while one of its calls waits to 
retry, the next attempt raises and nothing more is sent.
   
   The retry loops of the Rust client now check that the client is open after 
each backoff, before the next attempt, and raise `NO_ACTIVE_SESSION` if it is 
closed:
   
   - `with_retry`, which retries the initial ExecutePlan of an execution and 
the unary RPCs: AnalyzePlan, Config, Interrupt, CloneSession and the artifact 
status calls.
   - the retries of an artifact upload.
   
   This is the check that the reattach of a result stream already does before 
each attempt (SPARK-61187). The background ReleaseExecute is not changed.
   
   ### Why are the changes needed?
   
   The client was checked only when a call started. A call that retried, for 
example an ExecutePlan that got `UNAVAILABLE` from a server that went away, 
kept calling the server after `spark.stop()`, until the retry policy gave up. 
With the default policy (15 retries, backoffs up to 60 seconds) that takes 
minutes, and the thread of the call stays busy:
   
   ```
   spark = SparkSession.builder.remote("sc://localhost:1").getOrCreate()   # no 
server there
   t = threading.Thread(target=lambda: spark.range(2).count(), daemon=True); 
t.start()
   time.sleep(3); spark.stop(); t.join(15)
   # before: the thread is still retrying 15 seconds after stop()
   # after:  the count raised SparkConnectException [NO_ACTIVE_SESSION] at its 
next attempt
   ```
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. A call that waits to retry when its session is stopped raises 
`SparkConnectException` with `NO_ACTIVE_SESSION` at its next attempt, instead 
of retrying until the policy gives up.
   
   In PySpark, the ExecutePlan of a reattachable execution (the default) is 
retried by its iterator, which holds the gRPC stub of the closed channel. Its 
next attempt fails at once with `ValueError: Cannot invoke RPC on closed 
channel!` rather than `NO_ACTIVE_SESSION`. Either way, nothing more is sent.
   
   ### How was this patch tested?
   
   - New Rust test 
`retry_of_an_execution_whose_client_was_closed_raises_no_active_session` in 
`crates/spark-connect-core/tests/deadlines.rs`, with the mock server. The 
server fails every ExecutePlan with `UNAVAILABLE` under a policy of 1000 
retries. Once the execution has been retried, the client is closed, the call 
raises `NO_ACTIVE_SESSION`, and the server gets no more ExecutePlans. Without 
the change, the call keeps retrying, and the test fails at its 5-second bound.
   - The other tests of `deadlines.rs` (15 passed).
   - The lib tests of both crates (618 passed), the build of all tests, also 
with `wasm-udf`, the offline Python suites (2456 passed, 8 skipped), and the 
live drop-in and Arrow suites (217 passed) and live cases (11 passed) against a 
local Spark 4.3.0 server. Clippy reports no diagnostics in 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