This is an automated email from the ASF dual-hosted git repository.
HyukjinKwon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark-connect-rust.git
The following commit(s) were added to refs/heads/master by this push:
new 28b9573e [SPARK-61410][CONNECT][PYTHON] Raise NO_ACTIVE_SESSION from
the first call after the server-side session changed, as PySpark does
28b9573e is described below
commit 28b9573e39d6c08b86b66fbcfbbda24338b9b1f1
Author: Timothy Meehan <[email protected]>
AuthorDate: Thu Nov 12 08:29:52 2026 +0900
[SPARK-61410][CONNECT][PYTHON] Raise NO_ACTIVE_SESSION from the first call
after the server-side session changed, as PySpark does
### What changes were proposed in this pull request?
[SPARK-61410](https://issues.apache.org/jira/browse/SPARK-61410): raise
`NO_ACTIVE_SESSION` from the first call after the server-side session changed,
as PySpark does.
`SparkConnectClient::error_from_status` now returns `NO_ACTIVE_SESSION`
when the error of the server has an `errorId` and the client is closed, instead
of fetching the details of the error through the closed client and falling back
to the bare error. An `INVALID_HANDLE.SESSION_CHANGED` error closes the client
before this point, so the first call after the server restarted raises
`NO_ACTIVE_SESSION`.
### Why are the changes needed?
PySpark fetches the enriched error through its `_stub`, which raises
`NO_ACTIVE_SESSION` once the client is closed; that exception is not a
`grpc.RpcError`, so it replaces the error of the server. The Rust client raised
`INVALID_HANDLE.SESSION_CHANGED` from the first call and `NO_ACTIVE_SESSION`
only from the second.
Measured against an OSS Spark 4.3.0 Connect server on loopback, by setting
the client's observed server-side session ID (`_client._server_session_id`) to
a random UUID and calling `spark.range(3).collect()` twice (the server answers
with `SESSION_CHANGED`, as after a restart):
* pyspark-client 4.3.0: `SparkConnectException` `NO_ACTIVE_SESSION`, then
`SparkConnectException` `NO_ACTIVE_SESSION`.
* spark-connect-rust master 125654b: `UnknownException`
`INVALID_HANDLE.SESSION_CHANGED`, then `SparkConnectException`
`NO_ACTIVE_SESSION`.
* with this change: `SparkConnectException` `NO_ACTIVE_SESSION`, then
`SparkConnectException` `NO_ACTIVE_SESSION`.
### Does this PR introduce _any_ user-facing change?
Yes. The first call after the server-side session changed raises
`NO_ACTIVE_SESSION`, as PySpark does, instead of
`INVALID_HANDLE.SESSION_CHANGED`. A session-changed error without an `errorId`
is unchanged, as in PySpark.
### How was this patch tested?
The assertion of
`test_server_session_id_is_observed_and_a_changed_one_closes_the_session_as_pyspark`
in `python/tests/test_dropin_e2e.py` now expects `NO_ACTIVE_SESSION`. A new
test in `crates/spark-connect-core/tests/server_session.rs` (a loopback service
that fails a call with `INVALID_HANDLE.SESSION_CHANGED` and an `errorId`); it
fails without the change. `cargo test -p apache-spark-connect --release --lib`
(599 passed) and `-p apache-spark-connect-core --release` pass, all tests [...]
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5.5 and Claude Sonnet 5.5
This pull request and its description were written by Isaac.
Closes #517 from
tdcmeehan/SPARK-61410-no-active-session-after-session-change.
Authored-by: Timothy Meehan <[email protected]>
Signed-off-by: Hyukjin Kwon <[email protected]>
---
crates/spark-connect-core/src/client.rs | 10 +++++-
crates/spark-connect-core/tests/server_session.rs | 38 ++++++++++++++++++++++-
python/tests/test_dropin_e2e.py | 3 +-
3 files changed, 48 insertions(+), 3 deletions(-)
diff --git a/crates/spark-connect-core/src/client.rs
b/crates/spark-connect-core/src/client.rs
index 94040761..4bd37e11 100644
--- a/crates/spark-connect-core/src/client.rs
+++ b/crates/spark-connect-core/src/client.rs
@@ -1486,7 +1486,15 @@ impl SparkConnectClient {
return error;
};
let details = match &server.error_id {
- Some(error_id) => self.error_details(error_id).await,
+ Some(error_id) => {
+ // PySpark fetches the details through `_stub`, which raises
NO_ACTIVE_SESSION
+ // once the client is closed, as a session change closes it;
that replaces the
+ // error of the server.
+ if let Err(closed) = self.ensure_open() {
+ return closed;
+ }
+ self.error_details(error_id).await
+ }
None => None,
};
let display_stacktrace = self.display_server_stacktrace().await;
diff --git a/crates/spark-connect-core/tests/server_session.rs
b/crates/spark-connect-core/tests/server_session.rs
index 3621298b..98b10cd8 100644
--- a/crates/spark-connect-core/tests/server_session.rs
+++ b/crates/spark-connect-core/tests/server_session.rs
@@ -242,6 +242,11 @@ impl UnaryService<Vec<u8>> for Unary {
/// A `google.rpc.Status` with an `ErrorInfo` of `error_class`, as the server
sends the errors it
/// raises.
fn error_with_class(message: &str, error_class: &str) -> Status {
+ error_with_class_and_id(message, error_class, None)
+}
+
+/// [`error_with_class`] that also names the `errorId` under which the server
keeps the details.
+fn error_with_class_and_id(message: &str, error_class: &str, error_id:
Option<&str>) -> Status {
#[derive(Clone, PartialEq, prost::Message)]
struct ErrorInfo {
#[prost(string, tag = "1")]
@@ -260,10 +265,14 @@ fn error_with_class(message: &str, error_class: &str) ->
Status {
#[prost(message, repeated, tag = "3")]
details: Vec<prost_types::Any>,
}
+ let mut metadata = HashMap::from([("errorClass".to_string(),
error_class.to_string())]);
+ if let Some(id) = error_id {
+ metadata.insert("errorId".to_string(), id.to_string());
+ }
let info = ErrorInfo {
reason: "SESSION_CHANGED".into(),
domain: "org.apache.spark".into(),
- metadata: HashMap::from([("errorClass".to_string(),
error_class.to_string())]),
+ metadata,
};
let details = RpcStatus {
code: Code::Internal as i32,
@@ -475,6 +484,33 @@ async fn a_session_changed_error_closes_the_client() {
assert_eq!(error.get_condition().as_deref(), Some("NO_ACTIVE_SESSION"));
}
+#[tokio::test]
+async fn a_session_changed_error_that_has_details_raises_no_active_session() {
+ // The client is closed by the error, and the fetch of the details of the
error goes through
+ // it: PySpark raises the `NO_ACTIVE_SESSION` of that fetch from the call
that failed.
+ let fixture = Fixture::start().await;
+ let client = fixture.client().await;
+ fixture.state.failures.lock().unwrap().push_back((
+ "Config".to_string(),
+ error_with_class_and_id(
+ "The existing Spark server driver instance has restarted. Please
reconnect.",
+ "INVALID_HANDLE.SESSION_CHANGED",
+ Some("error-1"),
+ ),
+ ));
+
+ let error = client
+ .config(config_request(&client))
+ .await
+ .expect_err("a session change must raise");
+ assert_eq!(error.get_condition().as_deref(), Some("NO_ACTIVE_SESSION"));
+ assert!(client.is_closed());
+ assert!(fixture
+ .state
+
.requests_of::<spark_connect_proto::FetchErrorDetailsRequest>("FetchErrorDetails")
+ .is_empty());
+}
+
#[tokio::test]
async fn
a_client_without_session_tracking_passes_the_ids_of_its_requests_through() {
// The transport-injection stub sends the requests of the reference
client's session, which
diff --git a/python/tests/test_dropin_e2e.py b/python/tests/test_dropin_e2e.py
index 12fbdfc6..a12cdabb 100644
--- a/python/tests/test_dropin_e2e.py
+++ b/python/tests/test_dropin_e2e.py
@@ -308,7 +308,8 @@ def
test_server_session_id_is_observed_and_a_changed_one_closes_the_session_as_p
session._client._server_session_id = str(uuid.uuid4())
with pytest.raises(SparkConnectException) as error:
session.range(3).collect()
- assert "SESSION_CHANGED" in str(error.value)
+ # The close by the session change makes the fetch of the error's
details raise this.
+ assert "NO_ACTIVE_SESSION" in str(error.value)
assert session.is_stopped
finally:
session.release_session_on_close = False
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]