Skip to content

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

Open
cathleeny wants to merge 3 commits into
mainfrom
cathleeny/feat/connection-port
Open

cathleeny wants to merge 3 commits into
mainfrom
cathleeny/feat/connection-port

Conversation

@cathleeny

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. A review of the open Python, Node and Go port PRs found separate bugs in each copy.

  • Rust: ConnectionConfig::with_port(self, port: u16) -> Result<Self>.
  • C ABI: kernel_session_config_set_port(config, uint16_t port), for Go and ODBC. It validates eagerly, and the host setters re-check it, so a bad combination fails at config time.
  • pyo3: Session(..., port=None). napi: ConnectionOptions.port?: number. Both check type and range before any network I/O.
  • Telemetry: reports the applied port as host_info.port.

Rules (one implementation, fold_host_port in src/config.rs)

  • 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, and a bare IPv6 literal is bracketed.
  • A port already in the host wins, and a warning is logged when it differs.
  • InvalidArgument for: credentials in the host, an empty host, a path, query or fragment, or an out-of-range port in the host.
  • Error and log text replace everything up to the last @ with <redacted>, so a password containing / stays hidden.

Testing

  • cargo test: all pass, including a table test of the rules, credential redaction, the warning, with_port, the C ABI setter order, the connection fold and telemetry.
  • cargo clippy --all-targets -D warnings clean, also under --no-default-features --features tls-rustls; cargo fmt --check clean; make c-abi-test passes with new set_port cases.
  • pyo3: pytest tests/test_port.py passes.
  • napi's own Rust tests only link inside a Node host, so they run in CI.

Follow-up

The Python (databricks-sql-python#1071), Node (databricks-sql-nodejs#636) and Go (databricks-sql-go#581) port PRs will pass their port to this input instead of folding it themselves. 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
A requested port equal to the scheme default is treated as unset, so a port already in the host is used without a warning; the drivers rely on this, since they often pass the default as a plain value. The docs said a warning is logged whenever the two differ. They now say it is logged only for a non-default requested port, and a test pins the silent default case.

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: I found one low-severity issue. I checked the folding rules, credential redaction, eager validation order in the C ABI, and the pyo3/napi range checks, and all look correct and well tested.

Other findings

  • ⚪ Nit — with_port(0) resets applied_port to None even if an earlier with_port already folded a port into host, so telemetry host_info.port can disagree with the dialled host. This needs a contrived call sequence. Fix: leave applied_port unchanged for port 0, or derive it from host when telemetry is built. (Found by Claude Opus 5.5 · confirmed by the judge)

cathleeny added a commit to databricks/databricks-sql-go that referenced this pull request Nov 25, 2026
Move KERNEL_REV to 22ae6ec250837b38d0e3dc720310d4dcfb81fa98 (databricks/databricks-sql-kernel#505 head) and copy its header. The only header change is the set_port doc comment: a default port never warns about a port already in the host.

Signed-off-by: Cathleen Yan <58714163+cathleeny@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 dropped port 443 whenever https was not false, even for a host that already carries http:// (for example host 'http://localhost', port 443), where 443 is not the default; the kernel then connected to port 80. The driver now sends any explicit port, and the kernel, which knows the effective scheme, treats that scheme's default as a no-op. KERNEL_REV moves to 22ae6ec250837b38d0e3dc720310d4dcfb81fa98 (databricks/databricks-sql-kernel#505 head).

Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>

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

This branch was successfully deployed

1 active deployment
azure-prod — 22ae6ec2 Deployed Nov 25, 2026 by cathleeny via followup #4297
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.

1 participant