HyukjinKwon opened a new pull request, #440: URL: https://github.com/apache/spark-connect-rust/pull/440
### What changes were proposed in this pull request? [SPARK-61315](https://issues.apache.org/jira/browse/SPARK-61315): Keep the Spark Connect listener bus consistent when a listener fails, is removed or is re-added, as PySpark does. The native listener bus of the Rust client (`crates/spark-connect/src/streaming.rs`) gets five fixes: - A native listener that panics on the started event no longer unwinds `start()` or `toTable()`. Each listener is isolated: the panic is reported on stderr, and the other listeners still get the event. The query is returned, as PySpark's `post_to_all` does (it warns and goes on). The asynchronous path is unchanged. - Removing the last listener (and `close()`) waits for a started event that another thread is delivering, before the server's listener is removed. A removal of a non-last listener already waited for it. PySpark's bus holds its lock for that delivery, so its removal waits too. A worker's own event is not awaited, as before. - A failed server REMOVE before a new subscription is no longer ignored. `add_listener` returns the error without sending the ADD, and the registration stays marked as held, so that a retry removes it first. Previously the ADD was sent, and the server answers an ADD for a listener it still holds with no response (`SparkConnectStreamingQueryListenerHandler`, v4.3.0), so the add waited forever. - Any failure of the listener stream marks the server registration as held, transport failures included. The server drops a registration only on a later failed event send or on REMOVE, so after a transport failure on an idle session the next subscription now sends REMOVE first. Previously only callback and decoding failures marked it, and such a re-add could hang. - The listener stream no longer calls the session's progress handlers. PySpark's listener bus has no `Progress`, so each listener-bus stream that ended gave the handlers an extra `done` call. `execute_plan_unreported` (`session.rs`) carries the stream without handlers. The Python mock tests in `python/tests/streaming_listener_cases.py` now expect the REMOVE sent before the re-add after a failed stream. ### Why are the changes needed? - A native listener that panics on the started event made `start()` or `toTable()` raise while the query was already running on the server, so the caller got neither a handle nor a way to stop it. - `removeListener` of the last listener returned while the started callback of another thread was still running. - After a failed removal or a transport failure of the listener stream, `addListener` waited for ever for a response that the server never sends, and the later adds hung too. - After `close()` or `removeListener` of the last listener, the progress handlers saw one more `done` than PySpark's listener bus gives. The PySpark behaviour is taken from the official 4.3.0 source: `post_to_all` in `pyspark/sql/connect/streaming/query.py` (isolates each listener), the bus lock in `removeListener` in the same file, and `execute_command_as_iterator` in `pyspark/sql/connect/client/core.py` (no `Progress`). The server behaviour is taken from the `v4.3.0` tag of `SparkConnectStreamingQueryListenerHandler.scala`, `SparkConnectListenerBusListener`, and `ExecuteThreadRunner.shouldDelegateCompleteResponse`. The official client was not run for these cases: the re-add paths cannot be made to fail against a live server. ### Does this PR introduce _any_ user-facing change? Yes. A native listener that panics on the started event no longer makes `start()` or `toTable()` raise: the query is returned and the panic is reported on stderr. A failed server removal before a new subscription makes `addListener` raise, where it previously made the add hang. A re-add after a failed listener stream sends one extra REMOVE. The progress handlers are no longer called with an extra `done` for listener-bus streams. ### How was this patch tested? - Five new unit tests in `mod tests` of `streaming.rs`, before `stream_writer_partition_by`: `a_panicking_listener_on_the_started_event_does_not_unwind_the_start`, `last_removal_waits_for_a_started_event_in_delivery_from_another_thread`, `a_failed_removal_before_a_new_subscription_keeps_the_registration_held`, `a_transport_failure_marks_the_server_registration_held`, and `the_listener_event_stream_reports_no_progress_to_the_handlers`. Each of them fails when its fix is reverted (release build), and all five pass with the fix in release and debug builds. - `test_streaming_bus_errors_warn_once_clear_all_and_allow_reregistration` (`[transport]` case) and `test_streaming_listener_ended_stream_clears_registry_and_reopens[error]` now expect one REMOVE on the re-add. Both fail with the transport-failure fix reverted. - The offline Python suites (`test_dropin_offline.py`, `test_arrow_handoff.py`, `test_ml_offline.py`): 2927 passed, 8 skipped; the listener subset passes under pytest 9.2 too (57 passed). - Live: `e2e_streaming` (5 passed) and `test_dropin_e2e.py -k listener` (2 passed) against a Spark Connect 4.3.0 server. - The live Rust tests `e2e_streaming` (5 passed) and `e2e_integration` (19 passed) against a local Spark 4.3.0 server. - The lib tests of both crates (684 passed), the build of all tests, also with `wasm-udf`, the offline Python suites (2937 passed, 8 skipped), and the live drop-in and Arrow suites (241 passed) and live cases (14 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]
