HyukjinKwon opened a new pull request, #528: URL: https://github.com/apache/spark-connect-rust/pull/528
### What changes were proposed in this pull request? The host and the port of a Spark Connect URL (`sc://...`) are now read as `urllib.parse` reads them, with the `urlsplit` checks that PySpark's channel builder runs on the netloc. A `user_agent` longer than 2048 characters after URL escaping now raises `SparkConnectException`, as PySpark does. In `crates/spark-connect-core/src/channel.rs`: - The host is what follows the last `@`, so a userinfo such as `user@` or `user:pw@` is dropped (`_hostinfo`). - A bracketed host ends at its `]`, may be followed only by nothing or `:port`, and must be an IPv6 address (with an optional zone) or an IPvFuture; an IPv4 address or a name in brackets is an error (`_check_bracketed_netloc`, `_check_bracketed_host`). - Otherwise the host ends at the first `:`, so `a:1:2` has the bad port `1:2`. - The `urlsplit` checks run before the path and the params are read, as in `urllib`; the missing-host check and the port come after the params, as before. - The quoted text of the bad-port and bad-host messages has its secrets redacted with the existing `redact_url`, so `sc://localhost:x;token=SECRET` shows `'x;token=<redacted>'`. ### Why are the changes needed? The client accepted URLs that PySpark 4.3.0 rejects, and misread some valid ones: | URL | Before | PySpark 4.3.0 (and after) | |---|---|---| | `sc://localhost:15012:1/` | created; the RPC then retries forever | `ValueError: Port could not be cast to integer value as '15012:1'` | | `sc://a:1:2` | created | `ValueError: Port could not be cast to integer value as '1:2'` | | `sc://user@localhost:15012/;token=SECRET` | `PySparkRuntimeError: Failed to configure TLS` (host `user@localhost`) | connects to `localhost` in plaintext | | `sc://user:pw@:15002` | created | `PySparkValueError [INVALID_CONNECT_URL] ... Hostname is missing ...` | | `sc://[::1]x`, `sc://[::1]x:15002` | created | `ValueError: Invalid IPv6 URL` | | `sc://[1.2.3.4]:15002` | created | `ValueError: An IPv4 address cannot be in brackets` | | `sc://[localhost]:15002` | created | `ValueError: 'localhost' does not appear to be an IPv4 or IPv6 address` | A `user_agent` of more than 2048 characters raised `PySparkRuntimeError`, where PySpark raises `SparkConnectException` with the same message. This is a follow-up of SPARK-61389 (#479) and SPARK-61397 (#483). ### Does this PR introduce _any_ user-facing change? Yes. Connection strings that PySpark rejects are now rejected with PySpark's error instead of connecting or retrying forever, and a URL with a userinfo connects as PySpark does. A too long `user_agent` now raises `SparkConnectException`. ### How was this patch tested? - Rust unit tests in `channel.rs`, `authority_is_read_as_urllib_reads_it` (accepted hosts and ports, and 14 error messages including the redaction) and `a_too_long_user_agent_is_a_connect_exception`, both failing without this change. - Offline Python tests in `python/tests/test_dropin_offline.py`, `test_create_raises_for_an_authority_that_urllib_rejects_as_pyspark` and `test_create_raises_for_a_too_long_user_agent_as_pyspark`, both failing without this change. - A probe of 25 URLs through the reference client and this one: the same exception type and message for each. The missing-host message still quotes the `sc://` URL where PySpark quotes its rewritten `http://` URL, as before. - The offline suite (1837 passed), the Python e2e suite against a Spark 4.3.0 server (261 passed), the Rust e2e integration and session-catalog suites, the Rust library tests, the `--no-run` builds (with and without `wasm-udf`), `cargo fmt --check`, `scripts/audit_no_stubs.sh` and the ruff gates. ### 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]
