Skip to content

feat(config): accept a connection port and fold it into the host - #505

Merged
cathleeny merged 11 commits into
mainfrom
cathleeny/feat/connection-port
Nov 30, 2026
Merged

cathleeny merged 11 commits into
mainfrom
cathleeny/feat/connection-port

Conversation

@cathleeny

@cathleeny cathleeny commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds a connection port to the kernel so drivers stop folding a port into the host string themselves. Today Python, Node, Go and ODBC each do this with slightly different rules. Drivers now just pass the port.

  • Rust: ConnectionConfig::with_port(self, port: u16) -> Result<Self>.
  • C ABI: kernel_session_config_set_port(config, int64_t port), for Go and ODBC. It takes a wide integer so a caller passes its own value as is, and the kernel range-checks it. Validation is eager: a bad value or host/port combination fails at config time.
  • pyo3: Session(..., port=None). napi: ConnectionOptions.port?: number. Each maps its language's value onto config::PortValue, and one kernel function, config::port_from_value, decides: an integer in 0..=65535, and for a JS number also whole and finite.
  • Telemetry: reports the applied port as host_info.port.

Rules (fold_host_port in src/config.rs, on the transport's own URL parser, reqwest::Url)

  • Port 0, or the scheme's default (443 for https, 80 for http): the host is unchanged and not validated, as today.
  • Any other port is written as scheme://host:port.
  • A non-default port already in the host wins, with a warning when it differs. A default port in the host (h:443) counts as no port.
  • InvalidArgument for credentials, a path, query or fragment, or a host the parser rejects (empty, bad port, IPv6 without brackets).
  • Error and warning text never repeat the host, so no credential or token can reach them.

Testing

  • cargo test, cargo clippy --all-targets -D warnings (also with tls-rustls), cargo fmt --check and make c-abi-test pass.
  • pyo3 cargo test and napi cargo test --features dyn-symbols pass.
  • Live (dogfood): the Python, Go and Node port PRs, built against this kernel, were compared with each driver's main. A local CONNECT proxy mapped :8443 to the workspace's :443.
    • A custom port is dialed, and a port in the host wins.
    • Bad hosts are rejected before any request.
    • A 300k-row result (with CloudFetch) is fetched over the custom port.
    • The default, explicit-443, Reyden and Thrift paths behave as on main.

Follow-up

The Python (databricks-sql-python#1071), Node (databricks-sql-nodejs#636) and Go (databricks-sql-go#581) port PRs pass their port straight to this input. ODBC's FoldPortIntoHost can move the same way.

This pull request and its description were written by Isaac.

Bindings each folded a port into the host string themselves, with different rules. The kernel now does it once. ConnectionConfig::with_port applies a port (0 and the scheme default are no-ops and are not validated). Anything else is written as scheme://host:port. It is rejected with InvalidArgument for userinfo, an empty host, a path, query or fragment, or an embedded port outside 1-65535. An embedded port already in the host wins, with a warning when it differs. Error and log text redact credentials.

The C ABI gains kernel_session_config_set_port. It validates eagerly against the host set so far, and the host setters re-check it, so a bad combination fails at config time. pyo3 Session gains an optional port kwarg, and napi ConnectionOptions gains an optional port field. Both validate the value type and range before any network I/O. Connection telemetry reports the applied port as host_info.port.

Signed-off-by: cat23123 <58714163+cat23123@users.noreply.github.com>

Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 2 Low · 2 Nit

Looks good, with 3 low concerns. The fold rules, the eager C ABI checks, credential redaction and the binding wiring are all consistent, and tests at each tier cover them.

This overview is Claude Opus 5.5's initial take; some of its points were set aside by the cross-check judge and GPT-6.1 Sol added findings it doesn't mention — see the findings below.

Other findings

  • ⚪ Nit — The comment says the reported port is never a default, but with_port(443) records Some(443) and a test asserts this. Reword the comment to say only an explicitly applied port is reported. (Found by Claude Opus 5.5 · confirmed by the judge)
  • ⚪ Nit — Catching any Exception lets the test pass on an unrelated failure, so it does not show the promised InvalidArgument rejection. Require k.KernelError, assert its code is InvalidArgument, and keep the redaction assertion. (Found by GPT-6.1 Sol · confirmed by the judge)
🔀 1 finding considered and dismissed by the judge
  • 🔵 Low pyo3/src/session.rs:160 — Wrong-type port values (True, 8443.0, "8443") raise ValueError, but Python convention, and PyO3's own extraction, raise TypeError for a wrong type.
    Judge's evidence: return Err(pyo3::exceptions::PyValueError::new_err(INVALID));

Comment thread src/config.rs Resolved
Comment thread src/config.rs Resolved
URL parsers treat `\` as a path separator for http(s), so `https://h\path`
with a port was folded to `https://h\path:8443` and connected to the
default port. `\` now ends the authority like `/`, so such a host is
rejected with a port.

With the default port, a host with userinfo is left unvalidated, and a
`:` in the userinfo made the reported telemetry port fall back to 443.
The effective port is now read after the last `@`.

Also reword the telemetry port comment (an explicitly applied default
port is reported), and have the pyo3 credential test require a
KernelError with code InvalidArgument instead of any exception.

Signed-off-by: cat23123 <58714163+cat23123@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>
cathleeny added a commit to databricks/databricks-sql-nodejs that referenced this pull request Nov 25, 2026
The driver no longer folds `port` into the host. It passes the host through
and sends `port` to the napi binding, which folds it (kernel
databricks/databricks-sql-kernel#505, KERNEL_REV b5aac45d54bb4842b7e04dd7fbf2368216b6de4e).

The driver keeps `explicitPort()` validation (falsy means default, numeric
strings accepted, invalid throws HiveDriverError) and the `https: false`
scheme handling (sends `http://host`). It omits `port` when it is the default
for the scheme it sends (443 over HTTPS, 80 over HTTP), since the kernel
treats the default as a no-op.

Removed from the driver: embedded-port detection and conflict warning, IPv6
bracketing, userinfo handling, redactHost, and the path checks.

native/kernel/index.d.ts regenerated with `npm run build:native` against
KERNEL_REV; only the typed `port` field changed.

Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 Low

Looks good, with 1 low concern. The port-folding rules live in one place and are covered by tests, credential redaction is careful, and the C ABI, pyo3 and napi surfaces were updated together.

Comment thread src/config.rs Resolved

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 Low

Looks good, with 1 low concern: there is no end-to-end test that the folded port is used for the connection. The folding rules, credential redaction, the C ABI's eager validation in either setter order, and the binding range checks all match across Rust, C, pyo3 and napi.

Comment thread src/config.rs Resolved
pyo3 and napi each range-checked their own port value with their own
message. The kernel now owns the rule: a binding maps its language's
value onto `config::PortValue` (an integer, a float, or unsupported) and
`config::port_from_value` decides, so `8443.5`, `NaN`, out-of-range
values and non-numbers are rejected the same way everywhere. pyo3 still
raises ValueError like its other argument checks, and napi still gives
InvalidArgument; both now carry the kernel's message. The C ABI already
takes a `uint16_t`, so it is unchanged.

Signed-off-by: cat23123 <58714163+cat23123@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 3 Low

Looks good, with 1 low concern. Port folding is centralised with consistent validation and redaction. The C ABI checks are eager and leave the config unchanged on error, and the bindings pass their values to the shared port_from_value.

This overview is Claude Opus 5.5's initial take; GPT-6.1 Sol added findings it doesn't mention — see the findings below.

Comment thread src/config.rs Resolved
Comment thread src/config.rs Resolved
Comment thread src/config.rs Resolved
… ABI port

Replace the hand-written authority parsing (split_authority,
parse_embedded_port, IPv6 bracketing, redact_host) with the URL parser
the transport already uses. Behavior changes for a non-default port:
an IPv6 address must be bracketed, and a default port written in the
host (`h:443`) counts as no port, so the requested port is used. Errors
and the conflicting-port warning no longer repeat the host, so a
credential or token in it never reaches error or log text; the warning
now goes through klog like other kernel warnings.

kernel_session_config_set_port takes an int64_t, so C callers pass their
own integer as is and the kernel range-checks it with port_from_value.

Docs updated, and redundant unit tests removed.

Signed-off-by: cat23123 <58714163+cat23123@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 Low · 1 Nit

Looks good, with 1 low concern. Port folding, the eager C ABI validation and the binding mappings are consistent and well tested. Nit: the port paragraph in the pyo3 Session docstring has one overlong line (around 'logs a warning when they differ. A bad host/port…') that should be re-wrapped.

This overview is Claude Opus 5.5's initial take; GPT-6.1 Sol added findings it doesn't mention — see the findings below.

Other findings

  • ⚪ Nit — The public PortValue enum is exhaustive, unlike the module's other public enums, so adding a variant later would break downstream code. Mark it #[non_exhaustive]. Bindings only construct its variants, so this costs them nothing. (Found by Claude Opus 5.5 · confirmed by the judge)

Comment thread src/config.rs Resolved
…lisation

The path check ran on the parsed URL, which normalises dot segments, so
`https://h/private/..` passed with a custom port and lost its path. The
check now runs on the raw text after `scheme://`: any `/`, `?`, `#` or
`\` is a path, query or fragment.

Also mark `PortValue` `#[non_exhaustive]` and re-wrap the pyo3 `Session`
docstring.

Signed-off-by: cat23123 <58714163+cat23123@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 Nit

Looks good: 2 low concerns. The fold rules, eager validation in the C ABI, credential-safe error text and binding mappings are consistent and well tested at the unit level.

This overview is Claude Opus 5.5's initial take; some of its points were set aside by the cross-check judge — see the findings below.

Other findings

  • ⚪ Nit — applied_port is crate-private and set only in with_port, but host is a public field, so a Rust caller who edits host afterwards makes telemetry report a stale port. Compute the port from host when telemetry is built, or document that host must not change after with_port. (Found by Claude Opus 5.5 · confirmed by the judge)
🔀 1 finding considered and dismissed by the judge
  • 🔵 Low src/c_abi/session.rs:1762 — Every new test checks the folded host string, but no test confirms that a session built this way actually sends requests to host:port. Add a wiremock test t
    Judge's evidence: let connection = connection_config(connection, port)?;

@vuanhphung vuanhphung left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(src/auth/oauth/azure.rs:59):
Not in the diff, but this PR makes it reachable: host_authority keeps :port, so https://adb-1.dev.azuredatabricks.net:8443 fails the .dev.azuredatabricks.net suffix check and Azure SP M2M asks for the prod app's .default scope on dev/staging. Could you strip the port here (e.g. Url::parse(..).host_str(), as federation's host_of does) and add a :8443 case to effective_app_id_is_host_specific?

Comment thread src/config.rs Resolved
…e dev hosts with a port

Folding a port no longer lowercases or normalises the host: the port is
appended to the host as written, and a host with its own non-default port is
returned unchanged. This keeps the U2M token cache key the same as the
drivers' own folding produced.

The Azure dev/staging app id lookup now strips the port before the suffix
match, so `https://adb-1.dev.azuredatabricks.net:8443` gets the dev scope.

Signed-off-by: cat23123 <58714163+cat23123@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>
@cathleeny

Copy link
Copy Markdown
Collaborator Author

@vuanhphung re azure.rs:59: fixed in da0d57c. The suffix match now uses federation's host_of (port stripped), and effective_app_id_is_host_specific has a :8443 dev case.

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 Low · 1 Nit

Looks good, with 2 low concerns. The port folding, the eager C ABI checks in either call order, redacted error text and the per-binding mapping are consistent and well tested.

This overview is Claude Opus 5.5's initial take; some of its points were set aside by the cross-check judge and GPT-6.1 Sol added findings it doesn't mention — see the findings below.

Other findings

  • ⚪ Nit — applied_port is computed once in with_port, while host is a public field. Reassigning host afterwards would make telemetry report a stale port. This is unlikely in practice. Derive the port from the final host when building telemetry, or document the constraint. (Found by Claude Opus 5.5 · confirmed by the judge)
🔀 1 finding considered and dismissed by the judge
  • 🔵 Low pyo3/src/session.rs:156 — parse_port only accepts exact int instances, so integer-like values such as numpy.int64 raise ValueError even though Python treats them as ints via __i<br>Judge's evidence: /// an 'int' is an integer, and anything else (including 'bool', an 'int'`

Comment thread src/config.rs Resolved
…host

The URL parser ignores trailing spaces and control characters, so a host such
as `https://h ` passed validation and then became `https://h :8443`. Trim them
before appending the port.

Signed-off-by: cat23123 <58714163+cat23123@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 Low

Looks good: 3 low concerns, no blockers. The folding rules, the eager C ABI validation and the redaction of the host from errors are consistent across the Rust API, C ABI, pyo3 and napi, and each has tests.

This overview is Claude Opus 5.5's initial take; some of its points were set aside by the cross-check judge and GPT-6.1 Sol added findings it doesn't mention — see the findings below.

🔀 3 findings considered and dismissed by the judge
  • 🔵 Low src/telemetry/runtime.rs:413 — with_port(443) on https://h sets applied_port = Some(443), so telemetry reports a port that the docs call 'treated as unset'. Because ConnectionConfig.ho<br>Judge's evidence: port: connection.applied_port.map(i32::from),`
  • 🔵 Low src/config.rs:152 — The tests only compare the folded host string. Nothing checks that a session built with with_port actually connects to that port. Add a wiremock test that p
    Judge's evidence: assert_eq!(c.host, "https://h:8443");
  • 🔵 Low pyo3/src/session.rs:157 — parse_port only accepts exact PyInt instances, so numpy.int64(8443) or any other object that implements __index__ is reported as ValueError with the m
    Judge's evidence: if obj.is_instance_of::<PyBool>() || !obj.is_instance_of::<PyInt>() {

Comment thread src/config.rs Resolved
A host with its own non-default port was returned untrimmed, so `https://h:9000 `
kept the space. Trim once before validation so both branches use the trimmed host.

Signed-off-by: cat23123 <58714163+cat23123@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 Low

Looks good, with 2 low concerns. Port folding, eager validation in the C ABI and the binding mappings all hold up. Errors don't repeat the host, so credentials stay out of error text. Ordering is covered in both directions.

This overview is Claude Opus 5.5's initial take; some of its points were set aside by the cross-check judge — see the findings below.

🔀 1 finding considered and dismissed by the judge
  • 🔵 Low src/auth/oauth/azure.rs:61 — host_name now goes through host_of (Url::parse), so a host the parser rejects becomes "" and quietly falls back to the prod Azure app id. The old string-s
    Judge's evidence: super::federation::host_of(host) .map(|name| name.trim_end_matches('.').to_owned()) .unwrap_or_default()

Comment thread src/config.rs Resolved

This branch was successfully deployed

1 active deployment
azure-prod — dbfd616a Deployed Nov 30, 2026 by cathleeny via followup #4523
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants