HyukjinKwon opened a new pull request, #802:
URL: https://github.com/apache/spark-connect-rust/pull/802
### What changes were proposed in this pull request?
A follow-up of #769 (SPARK-61847), from a round-2 review of the transport
against grpcio and PySpark 4.3.0. Each item was probed on both clients through
recording and fault-injecting proxies.
**1. The user agent is sent in the client type only.**
- PySpark sends grpcio's own HTTP `user-agent` header, `grpc-python/1.85.1
grpc-c/58.0.0 (linux; chttp2)`. It carries the Spark user agent only in the
requests' `client_type`; see its `userAgent`, connect/client/core.py:450-477.
The drop-in sent the Spark user agent as the HTTP header.
- So a `user_agent` with a control character, such as `my%0Aagent` or `%7F`,
failed to connect with `ValueError: 'user_agent' parameter should not contain
control characters`, where PySpark's works. tonic now sends its own header, and
the client type keeps the user agent.
- A too-long user agent raised at `getOrCreate`. PySpark makes the session
and raises `SparkConnectException` at each request built with it. The drop-in
now does the same: `count`, `conf.get`, `version`, `schema` and `interruptAll`
raise; `addArtifacts`, `newSession` and `stop` do not.
- A `SPARK_CONNECT_USER_AGENT` that UTF-8 cannot encode raises PySpark's
`UnicodeEncodeError`, where the drop-in silently used `_SPARK_CONNECT_PYTHON`.
- The connection string drops raw tabs, CRs and LFs after its `sc://` check,
as Python's `urlsplit` does, where they failed.
**2. A connection has one 20 s deadline, as grpcio's.**
- `docs/compatibility.md` said "As in grpcio, a connection has 20 s" for the
TCP connection and the TLS handshake, but the TCP connection was abandoned
after 10 s.
- grpcio gives the TCP connection, the proxy's tunnel and the TLS handshake
one 20 s deadline. Probes: a listener whose accept queue is full, a TLS server
that accepts late, and a proxy that answers the CONNECT after 13 s.
- The drop-in now does the same: the proxy's tunnel takes its deadline
before tonic's timer of the handshake.
**3. A retry policy of no `max_backoff` keeps its backoff.**
- `RetryPolicyState::next_attempt` grew the backoff by its multiplier when
`max_backoff_ms` was None. PySpark keeps it at the initial backoff
(retries.py:146-150): `[100, 100, 100, 100, 100, None]` for a multiplier of
2.0, 4.0 or 0.5.
- Only direct users of the core crate's `set_retry_policy` could reach this.
`docs/compatibility.md` and `dev/parity/known-differences.md` describe these.
### Why are the changes needed?
So that the client connects with the user agents that PySpark connects with,
raises PySpark's errors at PySpark's points, and waits for a connection as long
as grpcio does.
### Does this PR introduce _any_ user-facing change?
Yes, as above:
- the HTTP `user-agent` header is tonic's own;
- user agents of control characters connect;
- a too-long one raises at each request;
- a connection may take 20 s;
- the backoff of no maximum stays at the initial one.
Documented differences that remain:
- `SPARK_CONNECT_USER_AGENT` is read once, when the session is made, as a
Rust `getenv` could race Python's `putenv`.
- grpcio staggers the addresses of a host by 250 ms, each with its own 20 s,
where the drop-in tries them in turn within one 20 s.
### How was this patch tested?
- **New tests.**
- In the core: four for the user agent, two for the connection string, and
one of the retries of other multipliers.
- `tests/proxy.rs`:
`a_tunnel_that_opens_late_has_the_rest_of_the_connect_deadline` and
`a_tcp_connection_has_the_whole_connect_deadline`. The latter skips on kernels
whose SYN retransmits are linear.
- The three deadline tests fail with the 10 s bounds put back.
- `test_dropin_offline.py`:
`test_a_too_long_user_agent_raises_at_each_request_as_pyspark`.
- The header expectations of `reattach_cleanup.rs` and
`test_arrow_handoff.py`.
- **Probes of both clients:**
- the client types of control-character user agents;
- each operation of a too-long user agent;
- the non-UTF-8 environment variable;
- the SYN, late-accept and slow-proxy timings;
- the backoffs of other policies.
- **Rust.**
- `cargo test -p apache-spark-connect -p apache-spark-connect-core
--release` (1630 passed) and `--features wasm-udf` (1332 passed);
- after the rebase on master, `-p apache-spark-connect-core` (308 passed);
- live `integration_test --ignored`, `e2e_integration`,
`e2e_session_catalog` and `e2e_reattach_drop`.
- **Python.**
- The offline suite of `coverage.yml`.
- `test_dropin_offline.py -k "user_agent or retry or connect or channel"`
on pandas 2 and 3.
- After the rebase, live `test_dropin_e2e.py` and `test_arrow_e2e.py` (313
passed).
- **Lint.** `cargo fmt --all --check`, `cargo +1.100.0 clippy -D warnings`,
ruff 0.14.0, `audit_no_stubs.sh` and `scripts/tests`.
### 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]