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

   ### What changes were proposed in this pull request?
   
   CPython unwinds a frame with its exception still set, so a native object can 
be dropped while an exception propagates. This applies to the last owner of a 
fitted model, a checkpoint or an execution, as in 
`est.fit(df).transform(bad).columns`. Its drop sends the object's finalizer 
request, whose hooks call Python: the call stack of 
`SPARK_CONNECT_DEBUG_CLIENT_CALL_STACK`, the start of the call's logs (since 
SPARK-62198), and the client's refresher.
   
   Calling Python with an exception set consumed it, which caused three 
failures:
   - CPython crashed with SIGSEGV in `PyException_SetTraceback(NULL)` when 
there was a handler in the frame;
   - otherwise the caller got `SystemError: error return without exception set` 
instead of PySpark's exception;
   - with the refresher, the model's deletion was not sent, so it stayed in the 
server's ML cache.
   
   A new helper, `deliver::preserving_pending_exception`, saves the pending 
exception and restores it from a guard's drop, as CPython's `slot_tp_finalize` 
does around `__del__`. An exception that the hooks leave set is reported as 
unraisable. The helper is applied at every native drop and finalizer path that 
calls Python:
   - the finalizer requests and the drop of a call;
   - the retry policies of a release or a checkpoint removal;
   - the done call of an execution's progress;
   - the Python-thread branches of the delivery functions.
   
   If the call stack cannot be read, the finalizer's request is not sent, as 
PySpark's `_execute_plan_request_with_metadata` raises there.
   
   ### Why are the changes needed?
   
   To fix a crash and wrong exceptions that SPARK-62198 (#916) made frequent. 
An official live test, 
`test_ml_e2e.py::test_ml_connect_estimators_and_scalers_take_vectors_not_arrays_as_pyspark`,
 failed with it intermittently.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes: the exception that propagates is PySpark's, the process does not crash, 
and the model's deletion is sent.
   
   ### How was this patch tested?
   
   - **New tests.** Offline tests in `test_dropin_offline.py` and 
`test_ml_offline.py` drop a checkpoint, an execution or a model while an 
exception propagates, with child-process variants for the crash. A live test in 
`test_ml_e2e.py` passes with official PySpark too. They fail on master: 12 of 
the 16 offline cases (`SystemError`, or SIGSEGV in the child), and 2 or 3 of 
the 3 live ones.
   - **Probes of both clients.** 24 live cases are identical to PySpark's. A 
reproduction crashed 8 of 20 runs on master and 0 of 20 with the fix.
   - **The official test above:** 20 of 20 runs pass.
   - **The usual checks:** the core tests (release and debug), clippy, rustdoc, 
the native server's crates, the tooling tests, the offline suite under 
coverage, and the 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]

Reply via email to