Skip to content

feat(napi): expose HTTP proxy + per-connection socket timeout ConnectionOptions - #129

Merged
msrathore-db merged 3 commits into
mainfrom
msrathore/krn-napi-proxy-socket-timeout
Jun 10, 2026
Merged

msrathore-db merged 3 commits into
mainfrom
msrathore/krn-napi-proxy-socket-timeout

Conversation

@msrathore-db

@msrathore-db msrathore-db commented Jun 5, 2026 •

Copy link
Copy Markdown
Collaborator

What

Adds two optional ConnectionOptions fields to the napi binding so a Node caller can configure HTTP routing programmatically, not just via env vars:

  • proxy?: string — an HTTP/HTTPS proxy URL (e.g. http://user:pass@host:port). Wired to reqwest::Proxy::all(url); basic-auth credentials embedded in the URL userinfo are honoured. Setting it routes all kernel traffic (session create, statement submit/poll, CloudFetch, close) through the proxy for that connection.
  • socketTimeoutMs?: number — per-connection read timeout (ms), mapped onto HttpConfig::request_timeout (reqwest's Client::timeout). Omitted ⇒ kernel default (120 s).

Why this is needed (and what already worked)

The kernel's internal client/http.rs proxy plumbing (Proxy::all + basic_auth + NoProxy bypass) was already complete, and env-var proxying already works — reqwest honours HTTPS_PROXY / HTTP_PROXY / NO_PROXY natively (it is not gated by default-features), and http.rs never calls .no_proxy(). The only gap was the public→internal bridge: config::ProxyConfig was an empty #[non_exhaustive] stub, so neither binding could pass an explicit proxy. This PR fills the public ProxyConfig (url / username / password / bypass_hosts, with a password-redacting Debug), projects it onto the internal HttpProxyConfig in build_proxy_config, and exposes it through napi ConnectionOptions. When proxy is unset, behaviour is unchanged and the env vars are still honoured.

This gives the Node driver Thrift-parity: the same ConnectionOptions.proxy that works on the Thrift backend now also works on the kernel/SEA backend.

Verification

  • cargo test (full, incl. doc tests) — 653 lib + proxy-projection tests pass, 0 failed; cargo clippy --all-targets -- -D warnings clean (lib + napi); cargo +stable fmt --all clean.
  • napi addon rebuilt; generated napi/index.d.ts carries proxy?: string + socketTimeoutMs?: number.
  • End-to-end via mitmproxy (Node driver useKernel: true against a live serverless SQL warehouse):
    • explicit proxy option (no env var) → all SEA calls (POST /sessions, POST /statements, GET …, DELETE …) intercepted by mitmproxy; SELECT returns the expected row.
    • dead proxy port → connection fails after retries (proves the explicit proxy is genuinely used, not bypassed).
    • HTTPS_PROXY env var (no explicit option) → also intercepted (confirms the env path still works).

Rebased onto current main.

This pull request and its description were written by Isaac.

…ionOptions

Add two new optional napi `ConnectionOptions` fields so the Node SEA
driver can configure HTTP routing programmatically instead of relying
solely on the `HTTPS_PROXY` env var:

- `proxy`: an HTTP/HTTPS proxy URL (e.g. `http://user:pass@host:port`)
  routed through `reqwest::Proxy::all`. Embedded basic-auth credentials
  are honoured. Omitted => current behaviour (env vars still respected).
- `socketTimeoutMs`: per-connection read timeout mapped onto the kernel
  `HttpConfig::request_timeout` (reqwest `Client::timeout`).

Plumbing:
- Give the public `config::ProxyConfig` real fields (url / username /
  password / bypass_hosts) with a redacting `Debug`, replacing the
  previously-empty reserved struct.
- Project `SessionConfig.proxy` onto the internal `HttpClientConfig`
  proxy in `build_proxy_config` (the internal http layer already
  supported proxy URL/auth/bypass; only the public->internal wiring was
  missing). Keep a destructuring binding so future field additions fail
  to compile rather than being silently dropped.

The internal `reqwest::ClientBuilder` proxy/timeout handling is
unchanged. Adds unit tests for the proxy projection and the
request_timeout -> read_timeout mapping.

Co-authored-by: Isaac
Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
@msrathore-db
msrathore-db force-pushed the msrathore/krn-napi-proxy-socket-timeout branch from f06fd34 to 3e04601 Compare June 10, 2026 09:10
…d inline wait)

The two `execute_direct_*_running_*` e2e tests asserted a `range(40e9)` scan
(~35s on the test warehouse) comes back `Running`. But `execute_direct` omits
`wait_timeout`, so the SEA server applies its default inline wait — which holds
far longer than the "~10s" an earlier comment assumed (up to the 50s SEA max).
A ~35s scan therefore sits right at that boundary and intermittently returns
`Completed`, panicking ("a 40B-row scan must be Running").

`rand()` makes the query non-cacheable (consecutive runs return different
counts), so a larger `range()` is genuinely proportionally slower — it cannot
be short-circuited by any result/IO cache:

- cancellable test: `range(1e12)` — cannot finish within ANY inline wait, so
  Running is deterministic; it is cancelled, so the full scan never runs.
- await-result test: `range(100e9)` (~90s) — clears the inline-wait ceiling
  with comfortable margin while `await_result` still completes in bounded time.

Verified locally: both return `Running` and pass.

Co-authored-by: Isaac
Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
`custom_http_headers_round_trip_succeeds` passed a made-up
`KernelE2E/1.0` User-Agent. Since a caller UA now REPLACES the kernel's
base UA (the JDBC prefix is no longer retained), and the SEA gateway
gates the INLINE_OR_EXTERNAL_LINKS result disposition on a `startsWith`
match against its allow-list of known driver prefixes, a non-allow-listed
prefix is rejected with HTTP 400 ("not a supported disposition").

Use the real Node connector prefix (`NodejsDatabricksSqlConnector/...`),
the way the NodeJS driver forwards its composed UA over napi. This both
makes the smoke test reflect real driver behaviour and confirms the
prefix is allow-listed for the disposition gate.

Verified against the live workspace: passes.

Co-authored-by: Isaac
Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
@msrathore-db
msrathore-db added this pull request to the merge queue Jun 10, 2026
Merged via the queue into main with commit df18a38 Jun 10, 2026
17 checks passed
msrathore-db added a commit to databricks/databricks-sql-nodejs that referenced this pull request Jun 10, 2026
…n on the kernel backend

Map the public Thrift-shaped `ConnectionOptions.proxy`
(`{protocol, host, port, auth}`) onto the kernel napi binding's
`proxy?: string`, so the SAME proxy connection option that works on the
Thrift backend now also routes kernel/SEA traffic through a proxy.

`buildKernelProxyOptions` composes `protocol://[user:pass@]host:port`,
percent-encoding any `auth.{username,password}` into the URL userinfo so
credentials with reserved characters survive; the kernel parses the
userinfo off and applies it as proxy basic-auth. Wired into
`buildKernelConnectionOptions` alongside the TLS / HTTP option builders.

The regenerated napi contract (`native/kernel/index.d.ts`) carries the
new `proxy?: string` and `socketTimeoutMs?: number` fields exposed by the
kernel PR (databricks/databricks-sql-kernel#129).

Note: env-var proxying (`HTTPS_PROXY` / `HTTP_PROXY` / `NO_PROXY`) already
worked on the kernel backend (reqwest honours it natively); this adds the
*programmatic* path for callers who cannot set process env vars.

Verified end-to-end via mitmproxy against a live serverless warehouse:
explicit `proxy` option (no env var) routes all SEA calls through the
proxy; a dead proxy port fails the connection (proving the proxy is used).

Co-authored-by: Isaac
Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>

This branch was previously deployed

1 inactive deployment
azure-prod — 120ac263 Deployed Jun 10, 2026 by msrathore-db via v0 TLS (mitmproxy) #168
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