HyukjinKwon opened a new pull request, #424: URL: https://github.com/apache/spark-connect-rust/pull/424
### What changes were proposed in this pull request? [SPARK-61241](https://issues.apache.org/jira/browse/SPARK-61241): keep a panicking Rust progress handler or listener from aborting the process or wedging the listener bus. - Progress: `ProgressTracker`'s `Drop` no longer calls the progress handlers while a panic unwinds. Before, a handler that panicked on an update and again on the final done call aborted the process ("panic in a destructor during cleanup"). Now the first panic propagates to the caller as an ordinary panic, and the process survives. The handlers still get the done call on normal ends. - Prefetching local iterator: `to_local_iterator(true)` reads the stream on a background task, where a panic of a progress handler ended the task and closed its channel, so the iterator stopped early and returned `Ok` with the rows so far (0 of 3 in a probe), a silent truncation. The iterator now joins the task once the channel closes and raises its panic in the caller (`resume_unwind`), as the iterator without prefetching does. - Listeners: a panic in a native Rust listener's `try_post_to_all`/`try_on_event` is a failure of the subscription, turned into a `SparkError` ("a streaming query listener panicked: ...") and reported through `on_stream_error` exactly like a returned error. A panic in `on_stream_error` is contained, so the remaining listeners are still told. The worker's registrations are cleared by a drop guard, so they are cleared also when the loop unwinds. - Re-subscription: after a callback or decoder failure the server still holds the listener, and it refuses a new `ADD_LISTENER_BUS_LISTENER` until `REMOVE_LISTENER_BUS_LISTENER` (the server acknowledges nothing and the add waits). `add_listener` therefore sends a best-effort remove when the bus has no live worker and the failed listener's server registration is still held, then opens a new subscription. It no longer appends a listener to a bus whose worker has ended. Rust API: no signature change. `add_listener`'s documented contract (a terminal failure clears all registrations, and a new add opens a new subscription) now holds for panics as it did for returned errors. ### Why are the changes needed? - A Rust progress handler that panics on an update and again when the execution unwinds (its done call runs during the unwinding) makes Rust abort the process with SIGABRT. Repro: a handler that panics on every call, running `spark.sql("SELECT reflect('java.lang.Thread','sleep',4000L)").collect()`. - With `to_local_iterator(true)`, the same panicking handler made the iterator end early without an error: the rows were cut short silently. - A native listener that panics in a callback unwinds its worker. The registrations stay on the bus, no `on_stream_error` is reported, and a listener added afterwards is appended to the dead bus and never gets an event. Both are Rust-only: PySpark has no native callback path, and the Python bridge already turns Python listener and progress exceptions into returned errors, which is unchanged. ### Does this PR introduce _any_ user-facing change? Yes, for Rust users of `apache-spark-connect`. A panicking progress handler no longer aborts the process, and a panicking native listener now ends its subscription with a reported error, so a later `add_listener` gets events. The Python drop-in is unchanged. ### How was this patch tested? - `progress::tests::a_handler_that_panics_does_not_abort_when_the_tracker_unwinds`, inserted before `detached_progress_registry_preserves_the_execution_recursion_bound`: a handler that panics on every call, with a tracker dropped while unwinding. The handler is called once and the process does not abort. It aborts with SIGABRT without the fix. - `streaming::tests::a_panicking_native_listener_fails_the_subscription_like_an_error`, inserted before `a_stale_worker_does_not_report_errors_to_a_new_generation`: a native listener panics on its first event. The subscription ends, `on_stream_error` gets the panic message, the registrations are cleared, no later event is read, and the server-held registration is marked for removal. It fails without the fix (the panic escapes the worker loop). - `test_a_panicking_progress_handler_reaches_the_caller_of_a_local_iterator` (new, `crates/spark-connect/tests/e2e_integration.rs`, before `test_dropped_stream_releases_its_execution`): a progress handler that panics on an update reaches the caller of `to_local_iterator`, with prefetching and without; without the fix the prefetching iterator returns `Ok` with 0 rows. - Live, against a Spark 4.3.0 Connect server (not a PR test): a native listener that panics on its first asynchronous event, and one that returns an error, each reported once; a listener added afterwards on the same session then got events of a new subscription. Before this change, the panic case reported nothing and the later listener never got events (from the code, not run live), and a returned error made the later add wait forever for the server's acknowledgement (seen live without the removal). The reviewer probe of the progress handler panic passes (`is_ok=false`, process survives). - Rust: `cargo test -p apache-spark-connect --lib` (release and debug), `cargo test -p apache-spark-connect --release --no-run` and the wasm-udf variant, `apache-spark-connect-core` tests, `e2e_streaming` against a live server. `cargo fmt --all --check`, clippy: no new warnings. - The live Rust tests `e2e_integration` (18 passed) and `e2e_streaming` (5 passed) against a local Spark 4.3.0 server. - The lib tests of both crates (666 passed), the build of all tests, also with `wasm-udf`, the offline Python suites (2819 passed, 8 skipped), and the live drop-in and Arrow suites (233 passed) and live cases (13 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]
