From c3c8a7db81cf275914bbb01752866acc49ee8e0b Mon Sep 17 00:00:00 2001 From: Aakash Saravanan Date: Wed, 18 Nov 2026 03:07:54 +0000 Subject: [PATCH 01/10] feat(kernel): expose HTTP/2 negotiation control Signed-off-by: Aakash Saravanan --- CHANGELOG.md | 1 + README.md | 1 + connector.go | 15 ++++ internal/backend/kernel/backend.go | 7 ++ internal/backend/kernel/config.go | 3 + .../kernel/include/databricks_kernel.h | 5 ++ internal/config/config.go | 19 +++++ kernel_config.go | 4 ++ kernel_config_test.go | 1 + kernel_experimental_test.go | 5 ++ kernel_http2_test.go | 69 ++++++++++++++++++ kernel_http2_transport_test.go | 70 +++++++++++++++++++ 12 files changed, 200 insertions(+) create mode 100644 kernel_http2_test.go create mode 100644 kernel_http2_transport_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index d5024d97c..219ab5fca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Fix OAuth M2M token requests hanging indefinitely when the token endpoint stops responding. Each request now uses a copy of `http.DefaultClient` with a timeout of at most 60s; `WithRetries` repeats failed fetches (databricks/databricks-sql-go#475). - Render non-finite FLOAT / DOUBLE values inside ARRAY / MAP / STRUCT results as the JSON strings `"NaN"`, `"Infinity"`, and `"-Infinity"` on both backends instead of failing row iteration. SQL NULL remains `null`; top-level floats remain numeric (databricks/databricks-sql-go#573). - **Behavior change:** Non-finite floating-point MAP keys use the same spellings as values on both backends. On the kernel backend, keys previously rendered as `"+Inf"` and `"-Inf"` now render as `"Infinity"` and `"-Infinity"`; `"NaN"` is unchanged. On Thrift, these keys previously failed row iteration (databricks/databricks-sql-go#573). +- Add kernel-only `WithEnableHTTP2` and DSN `enableHttp2`: HTTPS negotiates HTTP/2 with HTTP/1.1 fallback; `false` forces HTTP/1.1 for all kernel-owned HTTPS traffic. - Fix the module-root package conflict when building, linting, or running Gazelle with the `tools` build tag (databricks/databricks-sql-go#162). - **Behavior change:** Report declared DECIMAL precision and scale through `sql.ColumnType.DecimalSize()` on Thrift and SEA, including zero-row results. Tools such as ORM migrators can now act on these qualifiers (databricks/databricks-sql-go#500). - **Behavior change:** Support Arrow TIME results on Thrift and SEA as UTC `time.Time` values on `0001-01-01`, preserving precision and using clock-only nested JSON. TIME metadata now reports `TIME`/`time.Time` with no length, including empty and NULL-only results; previously Thrift reported `STRING`/`string` with unbounded length, and SEA reported an empty name with `*interface{}` (databricks/databricks-sql-go#505). diff --git a/README.md b/README.md index 77781de31..d531449dd 100644 --- a/README.md +++ b/README.md @@ -245,6 +245,7 @@ session parameter on both backends. | `catalog` | `WithInitialNamespace` | Both | | Initial catalog. Kernel applies it post-connect via `USE CATALOG`. | | `schema` | `WithInitialNamespace` | Both | | Initial schema. Kernel applies it post-connect via `USE SCHEMA`. | | `useKernel` | `WithUseKernel` | Both | `false` | Select the SEA/kernel backend. Requires a `databricks_kernel` build. | +| `enableHttp2` | `WithEnableHTTP2(b)` | SEA only | `true` (kernel default) | Negotiate HTTP/2 for all kernel-owned HTTPS traffic, with HTTP/1.1 fallback. `false` forces HTTP/1.1, including authentication, result downloads, and telemetry. | ### Query execution diff --git a/connector.go b/connector.go index 1b72c6190..aedaccb7d 100644 --- a/connector.go +++ b/connector.go @@ -326,6 +326,10 @@ func withUserConfig(ucfg config.UserConfig) ConnOption { enabled := *ucfg.EnableGeoSpatialSupportDSN kernelExperimental(c).EnableGeoSpatialSupport = &enabled } + if ucfg.EnableHTTP2DSN != nil { + enabled := *ucfg.EnableHTTP2DSN + kernelExperimental(c).EnableHTTP2 = &enabled + } } } @@ -711,6 +715,17 @@ func WithEnableGeoSpatialSupport(enabled bool) ConnOption { } } +// WithEnableHTTP2 controls HTTPS protocol negotiation on the kernel backend. +// The kernel defaults to HTTP/2 with HTTP/1.1 fallback. False forces HTTP/1.1 +// for all kernel-owned HTTPS requests, including authentication and downloads. +// The Thrift backend rejects this option. DSN: enableHttp2=false. +func WithEnableHTTP2(enabled bool) ConnOption { + return func(c *config.Config) { + value := enabled + kernelExperimental(c).EnableHTTP2 = &value + } +} + // WithKernelTrustedCerts adds a PEM CA-certificate bundle to the kernel's TLS // trust store on top of the system roots — for a corporate re-signing proxy or an // on-prem CA. Required (rather than relying on SSL_CERT_FILE) because the kernel's diff --git a/internal/backend/kernel/backend.go b/internal/backend/kernel/backend.go index d8e20d08e..27050f270 100644 --- a/internal/backend/kernel/backend.go +++ b/internal/backend/kernel/backend.go @@ -267,6 +267,13 @@ func (k *KernelBackend) OpenSession(ctx context.Context) error { if err := k.applyEnableGeoSpatialSupport(cfg); err != nil { return err } + if k.cfg.EnableHTTP2 != nil { + if err := call(func() C.KernelStatusCode { + return C.kernel_session_config_set_http2_enabled(cfg, C.bool(*k.cfg.EnableHTTP2)) + }); err != nil { + return fmt.Errorf("kernel: set_http2_enabled: %w", toConnError(err)) + } + } // Retry / backoff policy (WithRetries). See applyRetry. if err := k.applyRetry(cfg); err != nil { diff --git a/internal/backend/kernel/config.go b/internal/backend/kernel/config.go index c3f97ed83..f48add431 100644 --- a/internal/backend/kernel/config.go +++ b/internal/backend/kernel/config.go @@ -108,6 +108,9 @@ type Config struct { // sets this field and defaults it to false. EnableGeoSpatialSupport bool + // EnableHTTP2 leaves the kernel default in effect when nil; false forces HTTP/1.1. + EnableHTTP2 *bool + // TokenCacheEnabled controls the kernel's on-disk OAuth U2M token-cache persistence // (WithTokenCache / tokenCache DSN param). When false (the default), tokens are held // in memory only; when true, the refresh token is persisted encrypted to diff --git a/internal/backend/kernel/include/databricks_kernel.h b/internal/backend/kernel/include/databricks_kernel.h index 965c09b6b..56d47b2ce 100644 --- a/internal/backend/kernel/include/databricks_kernel.h +++ b/internal/backend/kernel/include/databricks_kernel.h @@ -366,6 +366,11 @@ KernelStatusCode kernel_session_config_set_custom_header(KernelSessionConfig* co KernelStatusCode kernel_session_config_set_sea_response_compression_enabled( KernelSessionConfig* config, bool enabled); +/* Negotiate HTTP/2 over HTTPS with HTTP/1.1 fallback (enabled by default). + * Set enabled=false to force HTTP/1.1 for all kernel-owned HTTPS requests. */ +KernelStatusCode kernel_session_config_set_http2_enabled(KernelSessionConfig* config, + bool enabled); + /* Configure the total timeout for one HTTP request, from connection start * through response-body completion. A separate 30s connection timeout also * applies, so connection establishment is bounded by the shorter limit. diff --git a/internal/config/config.go b/internal/config/config.go index f9c5143e2..5ccec964e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -144,6 +144,8 @@ type KernelExperimentalConfig struct { // struct Arrow value; false requests WKT / EWKT strings. A pointer // distinguishes the omitted value (default false) from an explicit setting. EnableGeoSpatialSupport *bool + // EnableHTTP2 is nil when the kernel owns the HTTPS protocol default. + EnableHTTP2 *bool } // DeepCopy returns a deep copy of the experimental config, or nil for a nil @@ -169,6 +171,10 @@ func (k *KernelExperimentalConfig) DeepCopy() *KernelExperimentalConfig { enabled := *k.EnableGeoSpatialSupport cp.EnableGeoSpatialSupport = &enabled } + if k.EnableHTTP2 != nil { + enabled := *k.EnableHTTP2 + cp.EnableHTTP2 = &enabled + } if k.MaxConnections != nil { max := *k.MaxConnections cp.MaxConnections = &max @@ -317,6 +323,8 @@ type UserConfig struct { // enableGeoSpatialSupport=true|false. Nil means omitted (the default is // false); the connector copies a present value into KernelExperimental. EnableGeoSpatialSupportDSN *bool + // EnableHTTP2DSN carries an explicit enableHttp2 DSN setting to the connector. + EnableHTTP2DSN *bool } // DeepCopy returns a true deep copy of UserConfig @@ -371,6 +379,10 @@ func (ucfg UserConfig) DeepCopy() UserConfig { enabled := *ucfg.EnableGeoSpatialSupportDSN result.EnableGeoSpatialSupportDSN = &enabled } + if ucfg.EnableHTTP2DSN != nil { + enabled := *ucfg.EnableHTTP2DSN + result.EnableHTTP2DSN = &enabled + } return result } @@ -556,6 +568,13 @@ func ParseDSN(dsn string) (UserConfig, error) { ucfg.EnableGeoSpatialSupportDSN = &enableGeoSpatialSupport } + if enabled, ok, err := params.extractAsBool("enableHttp2"); ok { + if err != nil { + return UserConfig{}, err + } + ucfg.EnableHTTP2DSN = &enabled + } + // Telemetry parameters if enableTelemetry, ok, err := params.extractAsBool("enableTelemetry"); ok { if err != nil { diff --git a/kernel_config.go b/kernel_config.go index 21a9f3cb1..a7399ce8a 100644 --- a/kernel_config.go +++ b/kernel_config.go @@ -230,6 +230,10 @@ func buildKernelConfig(cfg *config.Config, kauth kernel.Auth) kernel.Config { if ke.EnableGeoSpatialSupport != nil { kc.EnableGeoSpatialSupport = *ke.EnableGeoSpatialSupport } + if ke.EnableHTTP2 != nil { + enabled := *ke.EnableHTTP2 + kc.EnableHTTP2 = &enabled + } // U2M token-cache control (WithTokenCache / tokenCache DSN param): forward to kernel. kc.TokenCacheEnabled = ke.TokenCacheEnabled } diff --git a/kernel_config_test.go b/kernel_config_test.go index d8cd3c0c4..9c1db78d6 100644 --- a/kernel_config_test.go +++ b/kernel_config_test.go @@ -472,6 +472,7 @@ var kernelConfigFieldDisposition = map[string]string{ "UseArrowNativeDecimalDSN": "inert", // DSN carrier; kernel renders decimals exactly regardless "TokenCacheEnabledDSN": "inert", // DSN carrier; forwarded to KernelExperimental.TokenCacheEnabled "EnableGeoSpatialSupportDSN": "inert", // DSN carrier; forwarded to KernelExperimental.EnableGeoSpatialSupport + "EnableHTTP2DSN": "inert", // Fields promoted from the embedded CloudFetchConfig. The kernel does // CloudFetch internally (below the C ABI); each option is diff --git a/kernel_experimental_test.go b/kernel_experimental_test.go index a17647f13..3dee5d33c 100644 --- a/kernel_experimental_test.go +++ b/kernel_experimental_test.go @@ -27,6 +27,7 @@ import ( // deliberate decision and a setter in KernelBackend.OpenSession so it can't be // silently dropped. var kernelExperimentalFieldDisposition = map[string]string{ + "EnableHTTP2": "forwarded", "TLSTrustedCertsPEM": "forwarded", // set_tls_trusted_certs "TLSClientCertPEM": "forwarded", // set_tls_client_certificate (cert) "TLSClientKeyPEM": "forwarded", // set_tls_client_certificate (key) @@ -104,6 +105,9 @@ func TestWithKernelTLSOptionsSetExperimental(t *testing.T) { {"disable geospatial support", WithEnableGeoSpatialSupport(false), func(k *config.KernelExperimentalConfig) bool { return k.EnableGeoSpatialSupport != nil && !*k.EnableGeoSpatialSupport }}, + {"force HTTP/1.1", WithEnableHTTP2(false), func(k *config.KernelExperimentalConfig) bool { + return k.EnableHTTP2 != nil && !*k.EnableHTTP2 + }}, {"token cache", WithTokenCache(true), func(k *config.KernelExperimentalConfig) bool { return k.TokenCacheEnabled }}, @@ -143,6 +147,7 @@ func TestWithKernelOptionsRejectedOnThriftPath(t *testing.T) { {"max chunks in memory", WithKernelMaxChunksInMemory(4)}, {"decimal as float", WithKernelDecimalAsFloat(true)}, {"disable geospatial support", WithEnableGeoSpatialSupport(false)}, + {"force HTTP/1.1", WithEnableHTTP2(false)}, {"token cache", WithTokenCache(true)}, } for _, tc := range cases { diff --git a/kernel_http2_test.go b/kernel_http2_test.go new file mode 100644 index 000000000..411a2a60a --- /dev/null +++ b/kernel_http2_test.go @@ -0,0 +1,69 @@ +package dbsql + +import ( + "testing" + + "github.com/databricks/databricks-sql-go/internal/backend/kernel" + "github.com/databricks/databricks-sql-go/internal/config" +) + +func TestHTTP2OptionAndDSN(t *testing.T) { + for _, value := range []string{"", "true", "false"} { + t.Run("dsn="+value, func(t *testing.T) { + dsn := "token:test-token@example.databricks.com:443/sql/1.0/warehouses/test" + if value != "" { + dsn += "?enableHttp2=" + value + } + user, err := config.ParseDSN(dsn) + if err != nil { + t.Fatal(err) + } + cfg := baseKernelConfig() + withUserConfig(user.DeepCopy())(cfg) + got := buildKernelConfig(cfg, kernel.Auth{}).EnableHTTP2 + if value == "" { + if got != nil { + t.Fatal("omitted setting must leave the kernel default in effect") + } + return + } + want := value == "true" + if got == nil || *got != want { + t.Fatalf("EnableHTTP2 = %v, want %v", got, want) + } + WithEnableHTTP2(!want)(cfg) + if got := buildKernelConfig(cfg, kernel.Auth{}).EnableHTTP2; got == nil || *got != !want { + t.Fatal("connector option did not override the DSN setting") + } + withUserConfig(user)(cfg) + if got := buildKernelConfig(cfg, kernel.Auth{}).EnableHTTP2; got == nil || *got != want { + t.Fatal("DSN setting did not override the connector option") + } + }) + } + if _, err := config.ParseDSN("token:test-token@example.databricks.com:443/sql/1.0/warehouses/test?enableHttp2=invalid"); err == nil { + t.Fatal("invalid enableHttp2 must fail parsing") + } +} + +func TestHTTP2ConfigCopiesAreIndependent(t *testing.T) { + cfg := baseKernelConfig() + WithEnableHTTP2(false)(cfg) + copied := cfg.KernelExperimental.DeepCopy() + *copied.EnableHTTP2 = true + if *cfg.KernelExperimental.EnableHTTP2 { + t.Fatal("kernel config copy aliases the original HTTP/2 setting") + } + backendConfig := buildKernelConfig(cfg, kernel.Auth{}) + *backendConfig.EnableHTTP2 = true + if *cfg.KernelExperimental.EnableHTTP2 { + t.Fatal("backend config aliases the connector HTTP/2 setting") + } + value := false + user := config.UserConfig{EnableHTTP2DSN: &value} + userCopy := user.DeepCopy() + *userCopy.EnableHTTP2DSN = true + if *user.EnableHTTP2DSN { + t.Fatal("user config copy aliases the original HTTP/2 setting") + } +} diff --git a/kernel_http2_transport_test.go b/kernel_http2_transport_test.go new file mode 100644 index 000000000..22c91f6af --- /dev/null +++ b/kernel_http2_transport_test.go @@ -0,0 +1,70 @@ +//go:build cgo && databricks_kernel + +package dbsql + +import ( + "context" + "encoding/pem" + "net/http" + "net/http/httptest" + "testing" + "time" +) + +func TestKernelHTTPSProtocolNegotiation(t *testing.T) { + for _, tc := range []struct { + name string + serverHTTP2 bool + option []ConnOption + want int + }{ + {name: "default", serverHTTP2: true, want: 2}, + {name: "enabled", serverHTTP2: true, option: []ConnOption{WithEnableHTTP2(true)}, want: 2}, + {name: "opt out", serverHTTP2: true, option: []ConnOption{WithEnableHTTP2(false)}, want: 1}, + {name: "fallback", serverHTTP2: false, want: 1}, + } { + t.Run(tc.name, func(t *testing.T) { + versions := make(chan int, 4) + server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + versions <- r.ProtoMajor + w.Header().Set("Content-Type", "application/json") + _, _ = w.Write([]byte(`{"session_id":"http2-test"}`)) + })) + server.EnableHTTP2 = tc.serverHTTP2 + server.StartTLS() + defer server.Close() + ca := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: server.Certificate().Raw}) + options := []ConnOption{ + WithServerHostname(server.URL), + WithHTTPPath("/sql/1.0/warehouses/test"), + WithAccessToken("test-token"), + WithUseKernel(true), + WithKernelTrustedCerts(ca), + WithRetries(-1, 0, 0), + } + connector, err := NewConnector(append(options, tc.option...)...) + if err != nil { + t.Fatal(err) + } + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + connection, err := connector.Connect(ctx) + if err != nil { + t.Fatal(err) + } + if err := connection.Close(); err != nil { + t.Fatal(err) + } + for range 2 { + select { + case got := <-versions: + if got != tc.want { + t.Fatalf("HTTP/%d received, want HTTP/%d", got, tc.want) + } + case <-ctx.Done(): + t.Fatal(ctx.Err()) + } + } + }) + } +} From 01223609bc52c1e4a136b333ca25059167fa639c Mon Sep 17 00:00:00 2001 From: Aakash Saravanan Date: Wed, 18 Nov 2026 20:00:10 +0000 Subject: [PATCH 02/10] docs: describe HTTP/1.1 behavior with proxies Signed-off-by: Aakash Saravanan --- CHANGELOG.md | 2 +- README.md | 2 +- connector.go | 1 + internal/backend/kernel/include/databricks_kernel.h | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 219ab5fca..be185b88f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ - Fix OAuth M2M token requests hanging indefinitely when the token endpoint stops responding. Each request now uses a copy of `http.DefaultClient` with a timeout of at most 60s; `WithRetries` repeats failed fetches (databricks/databricks-sql-go#475). - Render non-finite FLOAT / DOUBLE values inside ARRAY / MAP / STRUCT results as the JSON strings `"NaN"`, `"Infinity"`, and `"-Infinity"` on both backends instead of failing row iteration. SQL NULL remains `null`; top-level floats remain numeric (databricks/databricks-sql-go#573). - **Behavior change:** Non-finite floating-point MAP keys use the same spellings as values on both backends. On the kernel backend, keys previously rendered as `"+Inf"` and `"-Inf"` now render as `"Infinity"` and `"-Infinity"`; `"NaN"` is unchanged. On Thrift, these keys previously failed row iteration (databricks/databricks-sql-go#573). -- Add kernel-only `WithEnableHTTP2` and DSN `enableHttp2`: HTTPS negotiates HTTP/2 with HTTP/1.1 fallback; `false` forces HTTP/1.1 for all kernel-owned HTTPS traffic. +- Add kernel-only `WithEnableHTTP2` and DSN `enableHttp2`: HTTPS negotiates HTTP/2 with HTTP/1.1 fallback; `false` forces HTTP/1.1 for all kernel-owned HTTPS traffic. Configured proxies force HTTP/1.1. - Fix the module-root package conflict when building, linting, or running Gazelle with the `tools` build tag (databricks/databricks-sql-go#162). - **Behavior change:** Report declared DECIMAL precision and scale through `sql.ColumnType.DecimalSize()` on Thrift and SEA, including zero-row results. Tools such as ORM migrators can now act on these qualifiers (databricks/databricks-sql-go#500). - **Behavior change:** Support Arrow TIME results on Thrift and SEA as UTC `time.Time` values on `0001-01-01`, preserving precision and using clock-only nested JSON. TIME metadata now reports `TIME`/`time.Time` with no length, including empty and NULL-only results; previously Thrift reported `STRING`/`string` with unbounded length, and SEA reported an empty name with `*interface{}` (databricks/databricks-sql-go#505). diff --git a/README.md b/README.md index d531449dd..4eb5df55c 100644 --- a/README.md +++ b/README.md @@ -245,7 +245,7 @@ session parameter on both backends. | `catalog` | `WithInitialNamespace` | Both | | Initial catalog. Kernel applies it post-connect via `USE CATALOG`. | | `schema` | `WithInitialNamespace` | Both | | Initial schema. Kernel applies it post-connect via `USE SCHEMA`. | | `useKernel` | `WithUseKernel` | Both | `false` | Select the SEA/kernel backend. Requires a `databricks_kernel` build. | -| `enableHttp2` | `WithEnableHTTP2(b)` | SEA only | `true` (kernel default) | Negotiate HTTP/2 for all kernel-owned HTTPS traffic, with HTTP/1.1 fallback. `false` forces HTTP/1.1, including authentication, result downloads, and telemetry. | +| `enableHttp2` | `WithEnableHTTP2(b)` | SEA only | `true` (kernel default) | Negotiate HTTP/2 for all kernel-owned HTTPS traffic, with HTTP/1.1 fallback. `false` forces HTTP/1.1, including authentication, result downloads, and telemetry. Configured proxies force HTTP/1.1 for the entire kernel client. | ### Query execution diff --git a/connector.go b/connector.go index aedaccb7d..3160f50a7 100644 --- a/connector.go +++ b/connector.go @@ -718,6 +718,7 @@ func WithEnableGeoSpatialSupport(enabled bool) ConnOption { // WithEnableHTTP2 controls HTTPS protocol negotiation on the kernel backend. // The kernel defaults to HTTP/2 with HTTP/1.1 fallback. False forces HTTP/1.1 // for all kernel-owned HTTPS requests, including authentication and downloads. +// Configured proxies force HTTP/1.1 for the entire kernel client. // The Thrift backend rejects this option. DSN: enableHttp2=false. func WithEnableHTTP2(enabled bool) ConnOption { return func(c *config.Config) { diff --git a/internal/backend/kernel/include/databricks_kernel.h b/internal/backend/kernel/include/databricks_kernel.h index 56d47b2ce..9781c6967 100644 --- a/internal/backend/kernel/include/databricks_kernel.h +++ b/internal/backend/kernel/include/databricks_kernel.h @@ -367,7 +367,7 @@ KernelStatusCode kernel_session_config_set_sea_response_compression_enabled( KernelSessionConfig* config, bool enabled); /* Negotiate HTTP/2 over HTTPS with HTTP/1.1 fallback (enabled by default). - * Set enabled=false to force HTTP/1.1 for all kernel-owned HTTPS requests. */ + * False or a configured proxy forces HTTP/1.1 for all kernel-owned HTTPS requests. */ KernelStatusCode kernel_session_config_set_http2_enabled(KernelSessionConfig* config, bool enabled); From f2addf71da686d970be1623b25f49c971c004843 Mon Sep 17 00:00:00 2001 From: Aakash Saravanan Date: Wed, 18 Nov 2026 20:08:38 +0000 Subject: [PATCH 03/10] docs: clarify environment proxy protocol settings Signed-off-by: Aakash Saravanan --- CHANGELOG.md | 2 +- README.md | 2 +- connector.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be185b88f..50c527ea6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ - Fix OAuth M2M token requests hanging indefinitely when the token endpoint stops responding. Each request now uses a copy of `http.DefaultClient` with a timeout of at most 60s; `WithRetries` repeats failed fetches (databricks/databricks-sql-go#475). - Render non-finite FLOAT / DOUBLE values inside ARRAY / MAP / STRUCT results as the JSON strings `"NaN"`, `"Infinity"`, and `"-Infinity"` on both backends instead of failing row iteration. SQL NULL remains `null`; top-level floats remain numeric (databricks/databricks-sql-go#573). - **Behavior change:** Non-finite floating-point MAP keys use the same spellings as values on both backends. On the kernel backend, keys previously rendered as `"+Inf"` and `"-Inf"` now render as `"Infinity"` and `"-Infinity"`; `"NaN"` is unchanged. On Thrift, these keys previously failed row iteration (databricks/databricks-sql-go#573). -- Add kernel-only `WithEnableHTTP2` and DSN `enableHttp2`: HTTPS negotiates HTTP/2 with HTTP/1.1 fallback; `false` forces HTTP/1.1 for all kernel-owned HTTPS traffic. Configured proxies force HTTP/1.1. +- Add kernel-only `WithEnableHTTP2` and DSN `enableHttp2`: HTTPS negotiates HTTP/2 with HTTP/1.1 fallback; `false` forces HTTP/1.1 for all kernel-owned HTTPS traffic. Configured proxies, including environment proxy variables, force HTTP/1.1. - Fix the module-root package conflict when building, linting, or running Gazelle with the `tools` build tag (databricks/databricks-sql-go#162). - **Behavior change:** Report declared DECIMAL precision and scale through `sql.ColumnType.DecimalSize()` on Thrift and SEA, including zero-row results. Tools such as ORM migrators can now act on these qualifiers (databricks/databricks-sql-go#500). - **Behavior change:** Support Arrow TIME results on Thrift and SEA as UTC `time.Time` values on `0001-01-01`, preserving precision and using clock-only nested JSON. TIME metadata now reports `TIME`/`time.Time` with no length, including empty and NULL-only results; previously Thrift reported `STRING`/`string` with unbounded length, and SEA reported an empty name with `*interface{}` (databricks/databricks-sql-go#505). diff --git a/README.md b/README.md index 4eb5df55c..1b5f85556 100644 --- a/README.md +++ b/README.md @@ -245,7 +245,7 @@ session parameter on both backends. | `catalog` | `WithInitialNamespace` | Both | | Initial catalog. Kernel applies it post-connect via `USE CATALOG`. | | `schema` | `WithInitialNamespace` | Both | | Initial schema. Kernel applies it post-connect via `USE SCHEMA`. | | `useKernel` | `WithUseKernel` | Both | `false` | Select the SEA/kernel backend. Requires a `databricks_kernel` build. | -| `enableHttp2` | `WithEnableHTTP2(b)` | SEA only | `true` (kernel default) | Negotiate HTTP/2 for all kernel-owned HTTPS traffic, with HTTP/1.1 fallback. `false` forces HTTP/1.1, including authentication, result downloads, and telemetry. Configured proxies force HTTP/1.1 for the entire kernel client. | +| `enableHttp2` | `WithEnableHTTP2(b)` | SEA only | `true` (kernel default) | Negotiate HTTP/2 for all kernel-owned HTTPS traffic, with HTTP/1.1 fallback. `false` forces HTTP/1.1, including authentication, result downloads, and telemetry. Configured proxies, including environment proxy variables, force HTTP/1.1 for the entire kernel client. | ### Query execution diff --git a/connector.go b/connector.go index 3160f50a7..a6e55a146 100644 --- a/connector.go +++ b/connector.go @@ -718,7 +718,7 @@ func WithEnableGeoSpatialSupport(enabled bool) ConnOption { // WithEnableHTTP2 controls HTTPS protocol negotiation on the kernel backend. // The kernel defaults to HTTP/2 with HTTP/1.1 fallback. False forces HTTP/1.1 // for all kernel-owned HTTPS requests, including authentication and downloads. -// Configured proxies force HTTP/1.1 for the entire kernel client. +// Configured proxies, including environment proxy variables, force HTTP/1.1 for the entire kernel client. // The Thrift backend rejects this option. DSN: enableHttp2=false. func WithEnableHTTP2(enabled bool) ConnOption { return func(c *config.Config) { From 18d210b08c128bc770a6d3153c4c161e7980f449 Mon Sep 17 00:00:00 2001 From: Aakash Saravanan Date: Wed, 18 Nov 2026 21:41:49 +0000 Subject: [PATCH 04/10] docs: describe HTTP/2 connection parameters Signed-off-by: Aakash Saravanan --- CONNECTION_PARAMETERS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONNECTION_PARAMETERS.md b/CONNECTION_PARAMETERS.md index 28624b378..8269706ca 100644 --- a/CONNECTION_PARAMETERS.md +++ b/CONNECTION_PARAMETERS.md @@ -46,6 +46,7 @@ wire. They are listed under [Kernel client-result confs](#kernel-client-result-c | `catalog` | `WithInitialNamespace` | ✅ | ✅ | | Initial catalog. Kernel applies it post-connect via `USE CATALOG`. | | `schema` | `WithInitialNamespace` | ✅ | ✅ | | Initial schema. Kernel applies it post-connect via `USE SCHEMA`. | | `useKernel` | `WithUseKernel` | ✅ | ✅ | `false` | Select the SEA/kernel backend. Requires a `databricks_kernel` build. | +| `enableHttp2` | `WithEnableHTTP2(b)` | ❌ | ✅ | `true` | Negotiate HTTP/2 for kernel-owned HTTPS with HTTP/1.1 fallback. `false` forces HTTP/1.1. Explicit or environment proxy configuration forces HTTP/1.1 for the entire client, including bypassed hosts. Omission retains the kernel default. | ## Authentication From e149e918df54a01b539e9747ca35915eb9132da6 Mon Sep 17 00:00:00 2001 From: Aakash Saravanan Date: Wed, 18 Nov 2026 22:00:02 +0000 Subject: [PATCH 05/10] test: isolate HTTP protocol negotiation from proxy environment Signed-off-by: Aakash Saravanan --- kernel_http2_transport_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/kernel_http2_transport_test.go b/kernel_http2_transport_test.go index 22c91f6af..c5baf6e97 100644 --- a/kernel_http2_transport_test.go +++ b/kernel_http2_transport_test.go @@ -7,11 +7,28 @@ import ( "encoding/pem" "net/http" "net/http/httptest" + "os" + "os/exec" + "strings" "testing" "time" ) func TestKernelHTTPSProtocolNegotiation(t *testing.T) { + const child = "DATABRICKS_HTTP2_DIRECT_TEST" + if os.Getenv(child) != "1" { + command := exec.Command(os.Args[0], "-test.run=^TestKernelHTTPSProtocolNegotiation$", "-test.v") //nolint:gosec // Re-executes this test binary only. + command.Env = append(os.Environ(), child+"=1", + "HTTP_PROXY=", "http_proxy=", "HTTPS_PROXY=", "https_proxy=", "ALL_PROXY=", "all_proxy=") + output, err := command.CombinedOutput() + if err != nil { + t.Fatalf("protocol helper failed: %v\n%s", err, output) + } + if strings.Count(string(output), "--- PASS: TestKernelHTTPSProtocolNegotiation/") != 4 { + t.Fatalf("protocol helper did not pass all four cases:\n%s", output) + } + return + } for _, tc := range []struct { name string serverHTTP2 bool From 0960f5182edb846aab58187705391506083f10e5 Mon Sep 17 00:00:00 2001 From: Aakash Saravanan Date: Wed, 18 Nov 2026 23:56:36 +0000 Subject: [PATCH 06/10] docs: clarify kernel HTTP protocol options Signed-off-by: Aakash Saravanan --- CHANGELOG.md | 2 +- CONNECTION_PARAMETERS.md | 2 +- README.md | 2 +- connector.go | 5 ++--- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50c527ea6..347778362 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ - Fix OAuth M2M token requests hanging indefinitely when the token endpoint stops responding. Each request now uses a copy of `http.DefaultClient` with a timeout of at most 60s; `WithRetries` repeats failed fetches (databricks/databricks-sql-go#475). - Render non-finite FLOAT / DOUBLE values inside ARRAY / MAP / STRUCT results as the JSON strings `"NaN"`, `"Infinity"`, and `"-Infinity"` on both backends instead of failing row iteration. SQL NULL remains `null`; top-level floats remain numeric (databricks/databricks-sql-go#573). - **Behavior change:** Non-finite floating-point MAP keys use the same spellings as values on both backends. On the kernel backend, keys previously rendered as `"+Inf"` and `"-Inf"` now render as `"Infinity"` and `"-Infinity"`; `"NaN"` is unchanged. On Thrift, these keys previously failed row iteration (databricks/databricks-sql-go#573). -- Add kernel-only `WithEnableHTTP2` and DSN `enableHttp2`: HTTPS negotiates HTTP/2 with HTTP/1.1 fallback; `false` forces HTTP/1.1 for all kernel-owned HTTPS traffic. Configured proxies, including environment proxy variables, force HTTP/1.1. +- Kernel HTTPS traffic negotiates HTTP/2 with HTTP/1.1 fallback. Set `WithEnableHTTP2(false)` or DSN `enableHttp2=false` to force HTTP/1.1. Configured proxies also force HTTP/1.1. - Fix the module-root package conflict when building, linting, or running Gazelle with the `tools` build tag (databricks/databricks-sql-go#162). - **Behavior change:** Report declared DECIMAL precision and scale through `sql.ColumnType.DecimalSize()` on Thrift and SEA, including zero-row results. Tools such as ORM migrators can now act on these qualifiers (databricks/databricks-sql-go#500). - **Behavior change:** Support Arrow TIME results on Thrift and SEA as UTC `time.Time` values on `0001-01-01`, preserving precision and using clock-only nested JSON. TIME metadata now reports `TIME`/`time.Time` with no length, including empty and NULL-only results; previously Thrift reported `STRING`/`string` with unbounded length, and SEA reported an empty name with `*interface{}` (databricks/databricks-sql-go#505). diff --git a/CONNECTION_PARAMETERS.md b/CONNECTION_PARAMETERS.md index 8269706ca..8019b97c6 100644 --- a/CONNECTION_PARAMETERS.md +++ b/CONNECTION_PARAMETERS.md @@ -46,7 +46,7 @@ wire. They are listed under [Kernel client-result confs](#kernel-client-result-c | `catalog` | `WithInitialNamespace` | ✅ | ✅ | | Initial catalog. Kernel applies it post-connect via `USE CATALOG`. | | `schema` | `WithInitialNamespace` | ✅ | ✅ | | Initial schema. Kernel applies it post-connect via `USE SCHEMA`. | | `useKernel` | `WithUseKernel` | ✅ | ✅ | `false` | Select the SEA/kernel backend. Requires a `databricks_kernel` build. | -| `enableHttp2` | `WithEnableHTTP2(b)` | ❌ | ✅ | `true` | Negotiate HTTP/2 for kernel-owned HTTPS with HTTP/1.1 fallback. `false` forces HTTP/1.1. Explicit or environment proxy configuration forces HTTP/1.1 for the entire client, including bypassed hosts. Omission retains the kernel default. | +| `enableHttp2` | `WithEnableHTTP2(b)` | ❌ | ✅ | `true` | Negotiate HTTP/2 for all kernel HTTPS traffic, with HTTP/1.1 fallback. `false` or an explicit/environment proxy forces HTTP/1.1, including bypassed hosts. | ## Authentication diff --git a/README.md b/README.md index 1b5f85556..8cc7a5771 100644 --- a/README.md +++ b/README.md @@ -245,7 +245,7 @@ session parameter on both backends. | `catalog` | `WithInitialNamespace` | Both | | Initial catalog. Kernel applies it post-connect via `USE CATALOG`. | | `schema` | `WithInitialNamespace` | Both | | Initial schema. Kernel applies it post-connect via `USE SCHEMA`. | | `useKernel` | `WithUseKernel` | Both | `false` | Select the SEA/kernel backend. Requires a `databricks_kernel` build. | -| `enableHttp2` | `WithEnableHTTP2(b)` | SEA only | `true` (kernel default) | Negotiate HTTP/2 for all kernel-owned HTTPS traffic, with HTTP/1.1 fallback. `false` forces HTTP/1.1, including authentication, result downloads, and telemetry. Configured proxies, including environment proxy variables, force HTTP/1.1 for the entire kernel client. | +| `enableHttp2` | `WithEnableHTTP2(b)` | SEA only | `true` | Negotiate HTTP/2 for all kernel HTTPS traffic, with HTTP/1.1 fallback. `false` or a configured proxy forces HTTP/1.1, including bypassed hosts. | ### Query execution diff --git a/connector.go b/connector.go index a6e55a146..05b560564 100644 --- a/connector.go +++ b/connector.go @@ -716,9 +716,8 @@ func WithEnableGeoSpatialSupport(enabled bool) ConnOption { } // WithEnableHTTP2 controls HTTPS protocol negotiation on the kernel backend. -// The kernel defaults to HTTP/2 with HTTP/1.1 fallback. False forces HTTP/1.1 -// for all kernel-owned HTTPS requests, including authentication and downloads. -// Configured proxies, including environment proxy variables, force HTTP/1.1 for the entire kernel client. +// Defaults to HTTP/2 with HTTP/1.1 fallback. False or a configured proxy forces +// HTTP/1.1 for all kernel traffic, including destinations that bypass the proxy. // The Thrift backend rejects this option. DSN: enableHttp2=false. func WithEnableHTTP2(enabled bool) ConnOption { return func(c *config.Config) { From 4724cad0334ff377776d54b6135573f43a1c3de3 Mon Sep 17 00:00:00 2001 From: Aakash Saravanan Date: Thu, 19 Nov 2026 17:29:34 +0000 Subject: [PATCH 07/10] test(kernel): focus HTTP/2 adapter coverage Signed-off-by: Aakash Saravanan --- CONNECTION_PARAMETERS.md | 2 +- README.md | 2 +- connector.go | 2 +- .../kernel/include/databricks_kernel.h | 8 +- kernel_config.go | 5 +- kernel_experimental_test.go | 61 +++++++++- kernel_http2_test.go | 69 ----------- kernel_http2_transport_test.go | 109 +++++++----------- 8 files changed, 107 insertions(+), 151 deletions(-) delete mode 100644 kernel_http2_test.go diff --git a/CONNECTION_PARAMETERS.md b/CONNECTION_PARAMETERS.md index 8019b97c6..af85045fc 100644 --- a/CONNECTION_PARAMETERS.md +++ b/CONNECTION_PARAMETERS.md @@ -46,7 +46,7 @@ wire. They are listed under [Kernel client-result confs](#kernel-client-result-c | `catalog` | `WithInitialNamespace` | ✅ | ✅ | | Initial catalog. Kernel applies it post-connect via `USE CATALOG`. | | `schema` | `WithInitialNamespace` | ✅ | ✅ | | Initial schema. Kernel applies it post-connect via `USE SCHEMA`. | | `useKernel` | `WithUseKernel` | ✅ | ✅ | `false` | Select the SEA/kernel backend. Requires a `databricks_kernel` build. | -| `enableHttp2` | `WithEnableHTTP2(b)` | ❌ | ✅ | `true` | Negotiate HTTP/2 for all kernel HTTPS traffic, with HTTP/1.1 fallback. `false` or an explicit/environment proxy forces HTTP/1.1, including bypassed hosts. | +| `enableHttp2` | `WithEnableHTTP2(b)` | ❌ | ✅ | `true` | Negotiate HTTP/2 for session HTTPS traffic, with HTTP/1.1 fallback. `false` or an explicit/environment proxy forces HTTP/1.1, including bypassed hosts. Telemetry may reuse an earlier session's HTTP client for the same host. | ## Authentication diff --git a/README.md b/README.md index 8cc7a5771..8616e5b74 100644 --- a/README.md +++ b/README.md @@ -245,7 +245,7 @@ session parameter on both backends. | `catalog` | `WithInitialNamespace` | Both | | Initial catalog. Kernel applies it post-connect via `USE CATALOG`. | | `schema` | `WithInitialNamespace` | Both | | Initial schema. Kernel applies it post-connect via `USE SCHEMA`. | | `useKernel` | `WithUseKernel` | Both | `false` | Select the SEA/kernel backend. Requires a `databricks_kernel` build. | -| `enableHttp2` | `WithEnableHTTP2(b)` | SEA only | `true` | Negotiate HTTP/2 for all kernel HTTPS traffic, with HTTP/1.1 fallback. `false` or a configured proxy forces HTTP/1.1, including bypassed hosts. | +| `enableHttp2` | `WithEnableHTTP2(b)` | SEA only | `true` | Negotiate HTTP/2 for session HTTPS traffic, with HTTP/1.1 fallback. `false` or a configured proxy forces HTTP/1.1, including bypassed hosts. Telemetry may reuse an earlier session's HTTP client for the same host. | ### Query execution diff --git a/connector.go b/connector.go index 05b560564..3ab987f89 100644 --- a/connector.go +++ b/connector.go @@ -717,7 +717,7 @@ func WithEnableGeoSpatialSupport(enabled bool) ConnOption { // WithEnableHTTP2 controls HTTPS protocol negotiation on the kernel backend. // Defaults to HTTP/2 with HTTP/1.1 fallback. False or a configured proxy forces -// HTTP/1.1 for all kernel traffic, including destinations that bypass the proxy. +// HTTP/1.1 for session traffic, including destinations that bypass the proxy. // The Thrift backend rejects this option. DSN: enableHttp2=false. func WithEnableHTTP2(enabled bool) ConnOption { return func(c *config.Config) { diff --git a/internal/backend/kernel/include/databricks_kernel.h b/internal/backend/kernel/include/databricks_kernel.h index 9781c6967..a3d47c280 100644 --- a/internal/backend/kernel/include/databricks_kernel.h +++ b/internal/backend/kernel/include/databricks_kernel.h @@ -366,10 +366,10 @@ KernelStatusCode kernel_session_config_set_custom_header(KernelSessionConfig* co KernelStatusCode kernel_session_config_set_sea_response_compression_enabled( KernelSessionConfig* config, bool enabled); -/* Negotiate HTTP/2 over HTTPS with HTTP/1.1 fallback (enabled by default). - * False or a configured proxy forces HTTP/1.1 for all kernel-owned HTTPS requests. */ -KernelStatusCode kernel_session_config_set_http2_enabled(KernelSessionConfig* config, - bool enabled); +/* Negotiate HTTP/2 for session HTTPS requests, with HTTP/1.1 fallback. + * Enabled by default. False or a configured proxy forces HTTP/1.1. */ +KernelStatusCode kernel_session_config_set_http2_enabled( + KernelSessionConfig* config, bool enabled); /* Configure the total timeout for one HTTP request, from connection start * through response-body completion. A separate 30s connection timeout also diff --git a/kernel_config.go b/kernel_config.go index a7399ce8a..9c3c1c22e 100644 --- a/kernel_config.go +++ b/kernel_config.go @@ -230,10 +230,7 @@ func buildKernelConfig(cfg *config.Config, kauth kernel.Auth) kernel.Config { if ke.EnableGeoSpatialSupport != nil { kc.EnableGeoSpatialSupport = *ke.EnableGeoSpatialSupport } - if ke.EnableHTTP2 != nil { - enabled := *ke.EnableHTTP2 - kc.EnableHTTP2 = &enabled - } + kc.EnableHTTP2 = ke.EnableHTTP2 // U2M token-cache control (WithTokenCache / tokenCache DSN param): forward to kernel. kc.TokenCacheEnabled = ke.TokenCacheEnabled } diff --git a/kernel_experimental_test.go b/kernel_experimental_test.go index 3dee5d33c..9e1ad0452 100644 --- a/kernel_experimental_test.go +++ b/kernel_experimental_test.go @@ -8,6 +8,7 @@ import ( "testing" "time" + "github.com/databricks/databricks-sql-go/internal/backend/kernel" "github.com/databricks/databricks-sql-go/internal/config" dbsqlerr "github.com/databricks/databricks-sql-go/errors" @@ -27,7 +28,7 @@ import ( // deliberate decision and a setter in KernelBackend.OpenSession so it can't be // silently dropped. var kernelExperimentalFieldDisposition = map[string]string{ - "EnableHTTP2": "forwarded", + "EnableHTTP2": "forwarded", // set_http2_enabled "TLSTrustedCertsPEM": "forwarded", // set_tls_trusted_certs "TLSClientCertPEM": "forwarded", // set_tls_client_certificate (cert) "TLSClientKeyPEM": "forwarded", // set_tls_client_certificate (key) @@ -71,6 +72,13 @@ func TestKernelExperimentalFieldsClassified(t *testing.T) { // KernelExperimental after applying a WithKernel* option is the signal the Thrift // branch keys off). func TestWithKernelTLSOptionsSetExperimental(t *testing.T) { + dsnOption := func(value string) ConnOption { + user, err := config.ParseDSN("token:test-token@example.databricks.com:443/sql/1.0/warehouses/test?enableHttp2=" + value) + if err != nil { + t.Fatal(err) + } + return withUserConfig(user) + } cases := []struct { name string opt ConnOption @@ -105,12 +113,21 @@ func TestWithKernelTLSOptionsSetExperimental(t *testing.T) { {"disable geospatial support", WithEnableGeoSpatialSupport(false), func(k *config.KernelExperimentalConfig) bool { return k.EnableGeoSpatialSupport != nil && !*k.EnableGeoSpatialSupport }}, + {"enable HTTP/2", WithEnableHTTP2(true), func(k *config.KernelExperimentalConfig) bool { + return k.EnableHTTP2 != nil && *k.EnableHTTP2 + }}, {"force HTTP/1.1", WithEnableHTTP2(false), func(k *config.KernelExperimentalConfig) bool { return k.EnableHTTP2 != nil && !*k.EnableHTTP2 }}, {"token cache", WithTokenCache(true), func(k *config.KernelExperimentalConfig) bool { return k.TokenCacheEnabled }}, + {"HTTP/2 DSN enabled", dsnOption("true"), func(k *config.KernelExperimentalConfig) bool { + return k.EnableHTTP2 != nil && *k.EnableHTTP2 + }}, + {"HTTP/2 DSN disabled", dsnOption("false"), func(k *config.KernelExperimentalConfig) bool { + return k.EnableHTTP2 != nil && !*k.EnableHTTP2 + }}, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { @@ -119,6 +136,12 @@ func TestWithKernelTLSOptionsSetExperimental(t *testing.T) { if cfg.KernelExperimental == nil { t.Fatalf("%s: KernelExperimental should be non-nil after the option", c.name) } + if cfg.KernelExperimental.EnableHTTP2 != nil { + got := buildKernelConfig(cfg, kernel.Auth{}).EnableHTTP2 + if got == nil || *got != *cfg.KernelExperimental.EnableHTTP2 { + t.Fatalf("buildKernelConfig lost EnableHTTP2: %v", got) + } + } if !c.verify(cfg.KernelExperimental) { t.Errorf("%s: option did not set the expected field(s): %+v", c.name, cfg.KernelExperimental) } @@ -126,6 +149,22 @@ func TestWithKernelTLSOptionsSetExperimental(t *testing.T) { } } +func TestKernelHTTP2DSNDefaultAndInvalid(t *testing.T) { + const dsn = "token:test-token@example.databricks.com:443/sql/1.0/warehouses/test" + user, err := config.ParseDSN(dsn) + if err != nil { + t.Fatal(err) + } + cfg := baseKernelConfig() + withUserConfig(user)(cfg) + if got := buildKernelConfig(cfg, kernel.Auth{}).EnableHTTP2; got != nil { + t.Fatal("omitted setting must leave the kernel default in effect") + } + if _, err := config.ParseDSN(dsn + "?enableHttp2=invalid"); err == nil { + t.Fatal("invalid enableHttp2 must fail parsing") + } +} + // End-to-end: setting a WithKernel* option WITHOUT WithUseKernel must make // Connect fail loud on the default (Thrift) path rather than silently connect // with a weaker-than-intended trust store. This exercises the connector's @@ -185,6 +224,8 @@ func TestWithKernelOptionsRejectedOnThriftPath(t *testing.T) { for _, dsn := range []string{ "token:supersecret@example.cloud.databricks.com:443/sql/1.0/endpoints/12346a5b5b0e123a?enableGeoSpatialSupport=true", "token:supersecret@example.cloud.databricks.com:443/sql/1.0/endpoints/12346a5b5b0e123a?enableGeoSpatialSupport=false", + "token:supersecret@example.cloud.databricks.com:443/sql/1.0/endpoints/12346a5b5b0e123a?enableHttp2=true", + "token:supersecret@example.cloud.databricks.com:443/sql/1.0/endpoints/12346a5b5b0e123a?enableHttp2=false", } { ucfg, err := config.ParseDSN(dsn) if err != nil { @@ -247,6 +288,7 @@ func TestWithKernelClientCertificateCopiesPEM(t *testing.T) { func TestKernelExperimentalDeepCopy(t *testing.T) { maxConnections := 37 enableGeoSpatialSupport := false + enableHTTP2 := false orig := &config.KernelExperimentalConfig{ TLSTrustedCertsPEM: []byte("ca-bundle"), TLSClientCertPEM: []byte("client-cert"), @@ -261,6 +303,7 @@ func TestKernelExperimentalDeepCopy(t *testing.T) { MaxConnections: &maxConnections, MaxChunksInMemory: 4, EnableGeoSpatialSupport: &enableGeoSpatialSupport, + EnableHTTP2: &enableHTTP2, TokenCacheEnabled: true, } cp := orig.DeepCopy() @@ -287,6 +330,22 @@ func TestKernelExperimentalDeepCopy(t *testing.T) { } else if cp.EnableGeoSpatialSupport == orig.EnableGeoSpatialSupport { t.Error("DeepCopy aliased EnableGeoSpatialSupport pointer") } + if cp.EnableHTTP2 == nil || *cp.EnableHTTP2 { + t.Fatalf("DeepCopy lost EnableHTTP2: %v", cp.EnableHTTP2) + } + *cp.EnableHTTP2 = true + if *orig.EnableHTTP2 { + t.Error("DeepCopy aliased EnableHTTP2 pointer") + } + user := config.UserConfig{EnableHTTP2DSN: &enableHTTP2} + userCopy := user.DeepCopy() + if userCopy.EnableHTTP2DSN == nil || *userCopy.EnableHTTP2DSN { + t.Fatalf("DeepCopy lost EnableHTTP2DSN: %v", userCopy.EnableHTTP2DSN) + } + *userCopy.EnableHTTP2DSN = true + if *user.EnableHTTP2DSN { + t.Error("DeepCopy aliased EnableHTTP2DSN pointer") + } if !cp.TokenCacheEnabled { t.Errorf("DeepCopy lost TokenCacheEnabled: %v", cp.TokenCacheEnabled) } diff --git a/kernel_http2_test.go b/kernel_http2_test.go deleted file mode 100644 index 411a2a60a..000000000 --- a/kernel_http2_test.go +++ /dev/null @@ -1,69 +0,0 @@ -package dbsql - -import ( - "testing" - - "github.com/databricks/databricks-sql-go/internal/backend/kernel" - "github.com/databricks/databricks-sql-go/internal/config" -) - -func TestHTTP2OptionAndDSN(t *testing.T) { - for _, value := range []string{"", "true", "false"} { - t.Run("dsn="+value, func(t *testing.T) { - dsn := "token:test-token@example.databricks.com:443/sql/1.0/warehouses/test" - if value != "" { - dsn += "?enableHttp2=" + value - } - user, err := config.ParseDSN(dsn) - if err != nil { - t.Fatal(err) - } - cfg := baseKernelConfig() - withUserConfig(user.DeepCopy())(cfg) - got := buildKernelConfig(cfg, kernel.Auth{}).EnableHTTP2 - if value == "" { - if got != nil { - t.Fatal("omitted setting must leave the kernel default in effect") - } - return - } - want := value == "true" - if got == nil || *got != want { - t.Fatalf("EnableHTTP2 = %v, want %v", got, want) - } - WithEnableHTTP2(!want)(cfg) - if got := buildKernelConfig(cfg, kernel.Auth{}).EnableHTTP2; got == nil || *got != !want { - t.Fatal("connector option did not override the DSN setting") - } - withUserConfig(user)(cfg) - if got := buildKernelConfig(cfg, kernel.Auth{}).EnableHTTP2; got == nil || *got != want { - t.Fatal("DSN setting did not override the connector option") - } - }) - } - if _, err := config.ParseDSN("token:test-token@example.databricks.com:443/sql/1.0/warehouses/test?enableHttp2=invalid"); err == nil { - t.Fatal("invalid enableHttp2 must fail parsing") - } -} - -func TestHTTP2ConfigCopiesAreIndependent(t *testing.T) { - cfg := baseKernelConfig() - WithEnableHTTP2(false)(cfg) - copied := cfg.KernelExperimental.DeepCopy() - *copied.EnableHTTP2 = true - if *cfg.KernelExperimental.EnableHTTP2 { - t.Fatal("kernel config copy aliases the original HTTP/2 setting") - } - backendConfig := buildKernelConfig(cfg, kernel.Auth{}) - *backendConfig.EnableHTTP2 = true - if *cfg.KernelExperimental.EnableHTTP2 { - t.Fatal("backend config aliases the connector HTTP/2 setting") - } - value := false - user := config.UserConfig{EnableHTTP2DSN: &value} - userCopy := user.DeepCopy() - *userCopy.EnableHTTP2DSN = true - if *user.EnableHTTP2DSN { - t.Fatal("user config copy aliases the original HTTP/2 setting") - } -} diff --git a/kernel_http2_transport_test.go b/kernel_http2_transport_test.go index c5baf6e97..e183765a8 100644 --- a/kernel_http2_transport_test.go +++ b/kernel_http2_transport_test.go @@ -7,81 +7,50 @@ import ( "encoding/pem" "net/http" "net/http/httptest" - "os" - "os/exec" - "strings" "testing" "time" ) -func TestKernelHTTPSProtocolNegotiation(t *testing.T) { - const child = "DATABRICKS_HTTP2_DIRECT_TEST" - if os.Getenv(child) != "1" { - command := exec.Command(os.Args[0], "-test.run=^TestKernelHTTPSProtocolNegotiation$", "-test.v") //nolint:gosec // Re-executes this test binary only. - command.Env = append(os.Environ(), child+"=1", - "HTTP_PROXY=", "http_proxy=", "HTTPS_PROXY=", "https_proxy=", "ALL_PROXY=", "all_proxy=") - output, err := command.CombinedOutput() - if err != nil { - t.Fatalf("protocol helper failed: %v\n%s", err, output) - } - if strings.Count(string(output), "--- PASS: TestKernelHTTPSProtocolNegotiation/") != 4 { - t.Fatalf("protocol helper did not pass all four cases:\n%s", output) - } - return +func TestKernelHTTP2OptOut(t *testing.T) { + versions := make(chan int, 4) + server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + versions <- r.ProtoMajor + w.Header().Set("Content-Type", "application/json") + _, _ = w.Write([]byte(`{"session_id":"http2-test"}`)) + })) + server.EnableHTTP2 = true + server.StartTLS() + defer server.Close() + ca := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: server.Certificate().Raw}) + connector, err := NewConnector( + WithServerHostname(server.URL), + WithHTTPPath("/sql/1.0/warehouses/test"), + WithAccessToken("test-token"), + WithUseKernel(true), + WithEnableHTTP2(false), + WithKernelTrustedCerts(ca), + WithRetries(-1, 0, 0), + ) + if err != nil { + t.Fatal(err) } - for _, tc := range []struct { - name string - serverHTTP2 bool - option []ConnOption - want int - }{ - {name: "default", serverHTTP2: true, want: 2}, - {name: "enabled", serverHTTP2: true, option: []ConnOption{WithEnableHTTP2(true)}, want: 2}, - {name: "opt out", serverHTTP2: true, option: []ConnOption{WithEnableHTTP2(false)}, want: 1}, - {name: "fallback", serverHTTP2: false, want: 1}, - } { - t.Run(tc.name, func(t *testing.T) { - versions := make(chan int, 4) - server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - versions <- r.ProtoMajor - w.Header().Set("Content-Type", "application/json") - _, _ = w.Write([]byte(`{"session_id":"http2-test"}`)) - })) - server.EnableHTTP2 = tc.serverHTTP2 - server.StartTLS() - defer server.Close() - ca := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: server.Certificate().Raw}) - options := []ConnOption{ - WithServerHostname(server.URL), - WithHTTPPath("/sql/1.0/warehouses/test"), - WithAccessToken("test-token"), - WithUseKernel(true), - WithKernelTrustedCerts(ca), - WithRetries(-1, 0, 0), - } - connector, err := NewConnector(append(options, tc.option...)...) - if err != nil { - t.Fatal(err) - } - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() - connection, err := connector.Connect(ctx) - if err != nil { - t.Fatal(err) - } - if err := connection.Close(); err != nil { - t.Fatal(err) - } - for range 2 { - select { - case got := <-versions: - if got != tc.want { - t.Fatalf("HTTP/%d received, want HTTP/%d", got, tc.want) - } - case <-ctx.Done(): - t.Fatal(ctx.Err()) - } + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + connection, err := connector.Connect(ctx) + if err != nil { + t.Fatal(err) + } + if err := connection.Close(); err != nil { + t.Fatal(err) + } + for range 2 { + select { + case got := <-versions: + if got != 1 { + t.Fatalf("HTTP/%d received, want HTTP/1.1", got) } - }) + case <-ctx.Done(): + t.Fatal(ctx.Err()) + } } } From 7b650791523c5c294ffe230455964f4a5fa73225 Mon Sep 17 00:00:00 2001 From: Aakash Saravanan Date: Thu, 19 Nov 2026 18:12:15 +0000 Subject: [PATCH 08/10] test(kernel): clarify HTTP/2 option coverage Signed-off-by: Aakash Saravanan --- CONNECTION_PARAMETERS.md | 2 +- README.md | 2 +- kernel_config_test.go | 2 +- kernel_experimental_test.go | 14 ++++++++------ kernel_http2_transport_test.go | 6 ++++++ 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/CONNECTION_PARAMETERS.md b/CONNECTION_PARAMETERS.md index af85045fc..cd071efd9 100644 --- a/CONNECTION_PARAMETERS.md +++ b/CONNECTION_PARAMETERS.md @@ -46,7 +46,7 @@ wire. They are listed under [Kernel client-result confs](#kernel-client-result-c | `catalog` | `WithInitialNamespace` | ✅ | ✅ | | Initial catalog. Kernel applies it post-connect via `USE CATALOG`. | | `schema` | `WithInitialNamespace` | ✅ | ✅ | | Initial schema. Kernel applies it post-connect via `USE SCHEMA`. | | `useKernel` | `WithUseKernel` | ✅ | ✅ | `false` | Select the SEA/kernel backend. Requires a `databricks_kernel` build. | -| `enableHttp2` | `WithEnableHTTP2(b)` | ❌ | ✅ | `true` | Negotiate HTTP/2 for session HTTPS traffic, with HTTP/1.1 fallback. `false` or an explicit/environment proxy forces HTTP/1.1, including bypassed hosts. Telemetry may reuse an earlier session's HTTP client for the same host. | +| `enableHttp2` | `WithEnableHTTP2(b)` | ❌ | ✅ | `true` | Negotiate HTTP/2 for session HTTPS traffic, with HTTP/1.1 fallback. `false` or an explicit/environment proxy forces HTTP/1.1, including bypassed hosts. | ## Authentication diff --git a/README.md b/README.md index 8616e5b74..ff85c86e3 100644 --- a/README.md +++ b/README.md @@ -245,7 +245,7 @@ session parameter on both backends. | `catalog` | `WithInitialNamespace` | Both | | Initial catalog. Kernel applies it post-connect via `USE CATALOG`. | | `schema` | `WithInitialNamespace` | Both | | Initial schema. Kernel applies it post-connect via `USE SCHEMA`. | | `useKernel` | `WithUseKernel` | Both | `false` | Select the SEA/kernel backend. Requires a `databricks_kernel` build. | -| `enableHttp2` | `WithEnableHTTP2(b)` | SEA only | `true` | Negotiate HTTP/2 for session HTTPS traffic, with HTTP/1.1 fallback. `false` or a configured proxy forces HTTP/1.1, including bypassed hosts. Telemetry may reuse an earlier session's HTTP client for the same host. | +| `enableHttp2` | `WithEnableHTTP2(b)` | SEA only | `true` | Negotiate HTTP/2 for session HTTPS traffic, with HTTP/1.1 fallback. `false` or a configured proxy forces HTTP/1.1, including bypassed hosts. | ### Query execution diff --git a/kernel_config_test.go b/kernel_config_test.go index 9c1db78d6..ac3bfe703 100644 --- a/kernel_config_test.go +++ b/kernel_config_test.go @@ -472,7 +472,7 @@ var kernelConfigFieldDisposition = map[string]string{ "UseArrowNativeDecimalDSN": "inert", // DSN carrier; kernel renders decimals exactly regardless "TokenCacheEnabledDSN": "inert", // DSN carrier; forwarded to KernelExperimental.TokenCacheEnabled "EnableGeoSpatialSupportDSN": "inert", // DSN carrier; forwarded to KernelExperimental.EnableGeoSpatialSupport - "EnableHTTP2DSN": "inert", + "EnableHTTP2DSN": "inert", // DSN carrier; forwarded to KernelExperimental.EnableHTTP2 // Fields promoted from the embedded CloudFetchConfig. The kernel does // CloudFetch internally (below the C ABI); each option is diff --git a/kernel_experimental_test.go b/kernel_experimental_test.go index 9e1ad0452..4c0e4a827 100644 --- a/kernel_experimental_test.go +++ b/kernel_experimental_test.go @@ -136,12 +136,6 @@ func TestWithKernelTLSOptionsSetExperimental(t *testing.T) { if cfg.KernelExperimental == nil { t.Fatalf("%s: KernelExperimental should be non-nil after the option", c.name) } - if cfg.KernelExperimental.EnableHTTP2 != nil { - got := buildKernelConfig(cfg, kernel.Auth{}).EnableHTTP2 - if got == nil || *got != *cfg.KernelExperimental.EnableHTTP2 { - t.Fatalf("buildKernelConfig lost EnableHTTP2: %v", got) - } - } if !c.verify(cfg.KernelExperimental) { t.Errorf("%s: option did not set the expected field(s): %+v", c.name, cfg.KernelExperimental) } @@ -160,6 +154,14 @@ func TestKernelHTTP2DSNDefaultAndInvalid(t *testing.T) { if got := buildKernelConfig(cfg, kernel.Auth{}).EnableHTTP2; got != nil { t.Fatal("omitted setting must leave the kernel default in effect") } + user, err = config.ParseDSN(dsn + "?enableHttp2=false") + if err != nil { + t.Fatal(err) + } + withUserConfig(user)(cfg) + if got := buildKernelConfig(cfg, kernel.Auth{}).EnableHTTP2; got == nil || *got { + t.Fatalf("explicit false was not forwarded to the kernel: %v", got) + } if _, err := config.ParseDSN(dsn + "?enableHttp2=invalid"); err == nil { t.Fatal("invalid enableHttp2 must fail parsing") } diff --git a/kernel_http2_transport_test.go b/kernel_http2_transport_test.go index e183765a8..5cc933b1c 100644 --- a/kernel_http2_transport_test.go +++ b/kernel_http2_transport_test.go @@ -7,11 +7,17 @@ import ( "encoding/pem" "net/http" "net/http/httptest" + "os" "testing" "time" ) func TestKernelHTTP2OptOut(t *testing.T) { + for _, name := range []string{"HTTP_PROXY", "http_proxy", "HTTPS_PROXY", "https_proxy", "ALL_PROXY", "all_proxy"} { + if os.Getenv(name) != "" { + t.Skipf("unset %s to test direct HTTP/2 negotiation", name) + } + } versions := make(chan int, 4) server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { versions <- r.ProtoMajor From fad2470664dfd9540a11a9833a833353e7b44480 Mon Sep 17 00:00:00 2001 From: Aakash Saravanan Date: Thu, 19 Nov 2026 21:07:52 +0000 Subject: [PATCH 09/10] test(kernel): verify HTTP/2 transport control Signed-off-by: Aakash Saravanan --- kernel_experimental_test.go | 15 +----- kernel_http2_transport_test.go | 90 +++++++++++++++++++--------------- 2 files changed, 52 insertions(+), 53 deletions(-) diff --git a/kernel_experimental_test.go b/kernel_experimental_test.go index 4c0e4a827..763ed9ec1 100644 --- a/kernel_experimental_test.go +++ b/kernel_experimental_test.go @@ -72,13 +72,6 @@ func TestKernelExperimentalFieldsClassified(t *testing.T) { // KernelExperimental after applying a WithKernel* option is the signal the Thrift // branch keys off). func TestWithKernelTLSOptionsSetExperimental(t *testing.T) { - dsnOption := func(value string) ConnOption { - user, err := config.ParseDSN("token:test-token@example.databricks.com:443/sql/1.0/warehouses/test?enableHttp2=" + value) - if err != nil { - t.Fatal(err) - } - return withUserConfig(user) - } cases := []struct { name string opt ConnOption @@ -122,12 +115,6 @@ func TestWithKernelTLSOptionsSetExperimental(t *testing.T) { {"token cache", WithTokenCache(true), func(k *config.KernelExperimentalConfig) bool { return k.TokenCacheEnabled }}, - {"HTTP/2 DSN enabled", dsnOption("true"), func(k *config.KernelExperimentalConfig) bool { - return k.EnableHTTP2 != nil && *k.EnableHTTP2 - }}, - {"HTTP/2 DSN disabled", dsnOption("false"), func(k *config.KernelExperimentalConfig) bool { - return k.EnableHTTP2 != nil && !*k.EnableHTTP2 - }}, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { @@ -143,7 +130,7 @@ func TestWithKernelTLSOptionsSetExperimental(t *testing.T) { } } -func TestKernelHTTP2DSNDefaultAndInvalid(t *testing.T) { +func TestKernelHTTP2DSN(t *testing.T) { const dsn = "token:test-token@example.databricks.com:443/sql/1.0/warehouses/test" user, err := config.ParseDSN(dsn) if err != nil { diff --git a/kernel_http2_transport_test.go b/kernel_http2_transport_test.go index 5cc933b1c..db4e7674f 100644 --- a/kernel_http2_transport_test.go +++ b/kernel_http2_transport_test.go @@ -12,51 +12,63 @@ import ( "time" ) -func TestKernelHTTP2OptOut(t *testing.T) { +func TestKernelHTTP2Transport(t *testing.T) { for _, name := range []string{"HTTP_PROXY", "http_proxy", "HTTPS_PROXY", "https_proxy", "ALL_PROXY", "all_proxy"} { if os.Getenv(name) != "" { t.Skipf("unset %s to test direct HTTP/2 negotiation", name) } } - versions := make(chan int, 4) - server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - versions <- r.ProtoMajor - w.Header().Set("Content-Type", "application/json") - _, _ = w.Write([]byte(`{"session_id":"http2-test"}`)) - })) - server.EnableHTTP2 = true - server.StartTLS() - defer server.Close() - ca := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: server.Certificate().Raw}) - connector, err := NewConnector( - WithServerHostname(server.URL), - WithHTTPPath("/sql/1.0/warehouses/test"), - WithAccessToken("test-token"), - WithUseKernel(true), - WithEnableHTTP2(false), - WithKernelTrustedCerts(ca), - WithRetries(-1, 0, 0), - ) - if err != nil { - t.Fatal(err) + cases := []struct { + name string + options []ConnOption + wantVersion int + }{ + {name: "default", wantVersion: 2}, + {name: "opt_out", options: []ConnOption{WithEnableHTTP2(false)}, wantVersion: 1}, } - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() - connection, err := connector.Connect(ctx) - if err != nil { - t.Fatal(err) - } - if err := connection.Close(); err != nil { - t.Fatal(err) - } - for range 2 { - select { - case got := <-versions: - if got != 1 { - t.Fatalf("HTTP/%d received, want HTTP/1.1", got) + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + versions := make(chan int, 4) + server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + versions <- r.ProtoMajor + w.Header().Set("Content-Type", "application/json") + _, _ = w.Write([]byte(`{"session_id":"http2-test"}`)) + })) + server.EnableHTTP2 = true + server.StartTLS() + defer server.Close() + ca := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: server.Certificate().Raw}) + options := []ConnOption{ + WithServerHostname(server.URL), + WithHTTPPath("/sql/1.0/warehouses/test"), + WithAccessToken("test-token"), + WithUseKernel(true), + WithKernelTrustedCerts(ca), + WithRetries(-1, 0, 0), } - case <-ctx.Done(): - t.Fatal(ctx.Err()) - } + connector, err := NewConnector(append(options, tc.options...)...) + if err != nil { + t.Fatal(err) + } + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + connection, err := connector.Connect(ctx) + if err != nil { + t.Fatal(err) + } + if err := connection.Close(); err != nil { + t.Fatal(err) + } + for range 2 { + select { + case got := <-versions: + if got != tc.wantVersion { + t.Fatalf("HTTP/%d received, want HTTP/%d", got, tc.wantVersion) + } + case <-ctx.Done(): + t.Fatal(ctx.Err()) + } + } + }) } } From f8a512398798d07e374de19e2795657c395c16b6 Mon Sep 17 00:00:00 2001 From: Aakash Saravanan Date: Fri, 20 Nov 2026 02:43:18 +0000 Subject: [PATCH 10/10] refactor(kernel): align HTTP/2 option helpers and tests Signed-off-by: Aakash Saravanan --- connector_test.go | 13 +++++++++++ internal/backend/kernel/backend.go | 20 +++++++++++----- internal/config/config_test.go | 33 ++++++++++++++++++++++++++ kernel_experimental_test.go | 37 ------------------------------ 4 files changed, 60 insertions(+), 43 deletions(-) diff --git a/connector_test.go b/connector_test.go index 684a8646f..62794b02c 100644 --- a/connector_test.go +++ b/connector_test.go @@ -464,6 +464,19 @@ func TestNewConnector(t *testing.T) { assert.False(t, *coni.cfg.KernelExperimental.EnableGeoSpatialSupport) }) + t.Run("Connector test enableHttp2=false DSN param preserves explicit false", func(t *testing.T) { + ucfg, err := config.ParseDSN("token:supersecret@databricks-host:443/sql/1.0/endpoints/abc?enableHttp2=false") + require.NoError(t, err) + con, err := NewConnector(withUserConfig(ucfg)) + require.NoError(t, err) + + coni, ok := con.(*connector) + require.True(t, ok) + got := buildKernelConfig(coni.cfg, kernel.Auth{}).EnableHTTP2 + require.NotNil(t, got) + assert.False(t, *got) + }) + t.Run("Connector test WithTransport sets HTTPClient in CloudFetchConfig", func(t *testing.T) { host := "databricks-host" accessToken := "token" diff --git a/internal/backend/kernel/backend.go b/internal/backend/kernel/backend.go index 27050f270..529750f63 100644 --- a/internal/backend/kernel/backend.go +++ b/internal/backend/kernel/backend.go @@ -267,12 +267,8 @@ func (k *KernelBackend) OpenSession(ctx context.Context) error { if err := k.applyEnableGeoSpatialSupport(cfg); err != nil { return err } - if k.cfg.EnableHTTP2 != nil { - if err := call(func() C.KernelStatusCode { - return C.kernel_session_config_set_http2_enabled(cfg, C.bool(*k.cfg.EnableHTTP2)) - }); err != nil { - return fmt.Errorf("kernel: set_http2_enabled: %w", toConnError(err)) - } + if err := k.applyEnableHTTP2(cfg); err != nil { + return err } // Retry / backoff policy (WithRetries). See applyRetry. @@ -475,6 +471,18 @@ func (k *KernelBackend) applyEnableGeoSpatialSupport(cfg *C.KernelSessionConfig) return nil } +func (k *KernelBackend) applyEnableHTTP2(cfg *C.KernelSessionConfig) error { + if k.cfg.EnableHTTP2 == nil { + return nil + } + if err := call(func() C.KernelStatusCode { + return C.kernel_session_config_set_http2_enabled(cfg, C.bool(*k.cfg.EnableHTTP2)) + }); err != nil { + return fmt.Errorf("kernel: set_http2_enabled: %w", toConnError(err)) + } + return nil +} + // applyRetry forwards the driver's HTTP retry / backoff policy to the session // config. A no-op when Config.Retry is nil, so the kernel's own default policy // (exponential backoff with jitter, 5 retries, 1s..60s, 900s budget) is preserved diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 518ccaf29..feee451d1 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -730,6 +730,39 @@ func TestParseDSNEnableGeoSpatialSupport(t *testing.T) { } } +func TestParseDSNEnableHTTP2(t *testing.T) { + base := "token:supersecret@example.cloud.databricks.com:443/sql/1.0/endpoints/abc" + for _, tc := range []struct { + name string + query string + want *bool + }{ + {name: "omitted", query: "", want: nil}, + {name: "enabled", query: "?enableHttp2=true", want: func() *bool { v := true; return &v }()}, + {name: "disabled", query: "?enableHttp2=false", want: func() *bool { v := false; return &v }()}, + } { + t.Run(tc.name, func(t *testing.T) { + got, err := ParseDSN(base + tc.query) + if err != nil { + t.Fatal(err) + } + if tc.want == nil { + if got.EnableHTTP2DSN != nil { + t.Errorf("EnableHTTP2DSN = %v, want nil", *got.EnableHTTP2DSN) + } + return + } + if got.EnableHTTP2DSN == nil || *got.EnableHTTP2DSN != *tc.want { + t.Errorf("EnableHTTP2DSN = %v, want %v", got.EnableHTTP2DSN, *tc.want) + } + }) + } + + if _, err := ParseDSN(base + "?enableHttp2=invalid"); err == nil { + t.Error("malformed enableHttp2 should fail DSN parsing") + } +} + func TestParseDSNQueryTimeoutRange(t *testing.T) { if strconv.IntSize < 64 { t.Skip("strconv.Atoi rejects these values before the range check on 32-bit platforms") diff --git a/kernel_experimental_test.go b/kernel_experimental_test.go index 763ed9ec1..435f6e4f0 100644 --- a/kernel_experimental_test.go +++ b/kernel_experimental_test.go @@ -8,7 +8,6 @@ import ( "testing" "time" - "github.com/databricks/databricks-sql-go/internal/backend/kernel" "github.com/databricks/databricks-sql-go/internal/config" dbsqlerr "github.com/databricks/databricks-sql-go/errors" @@ -106,9 +105,6 @@ func TestWithKernelTLSOptionsSetExperimental(t *testing.T) { {"disable geospatial support", WithEnableGeoSpatialSupport(false), func(k *config.KernelExperimentalConfig) bool { return k.EnableGeoSpatialSupport != nil && !*k.EnableGeoSpatialSupport }}, - {"enable HTTP/2", WithEnableHTTP2(true), func(k *config.KernelExperimentalConfig) bool { - return k.EnableHTTP2 != nil && *k.EnableHTTP2 - }}, {"force HTTP/1.1", WithEnableHTTP2(false), func(k *config.KernelExperimentalConfig) bool { return k.EnableHTTP2 != nil && !*k.EnableHTTP2 }}, @@ -130,30 +126,6 @@ func TestWithKernelTLSOptionsSetExperimental(t *testing.T) { } } -func TestKernelHTTP2DSN(t *testing.T) { - const dsn = "token:test-token@example.databricks.com:443/sql/1.0/warehouses/test" - user, err := config.ParseDSN(dsn) - if err != nil { - t.Fatal(err) - } - cfg := baseKernelConfig() - withUserConfig(user)(cfg) - if got := buildKernelConfig(cfg, kernel.Auth{}).EnableHTTP2; got != nil { - t.Fatal("omitted setting must leave the kernel default in effect") - } - user, err = config.ParseDSN(dsn + "?enableHttp2=false") - if err != nil { - t.Fatal(err) - } - withUserConfig(user)(cfg) - if got := buildKernelConfig(cfg, kernel.Auth{}).EnableHTTP2; got == nil || *got { - t.Fatalf("explicit false was not forwarded to the kernel: %v", got) - } - if _, err := config.ParseDSN(dsn + "?enableHttp2=invalid"); err == nil { - t.Fatal("invalid enableHttp2 must fail parsing") - } -} - // End-to-end: setting a WithKernel* option WITHOUT WithUseKernel must make // Connect fail loud on the default (Thrift) path rather than silently connect // with a weaker-than-intended trust store. This exercises the connector's @@ -326,15 +298,6 @@ func TestKernelExperimentalDeepCopy(t *testing.T) { if *orig.EnableHTTP2 { t.Error("DeepCopy aliased EnableHTTP2 pointer") } - user := config.UserConfig{EnableHTTP2DSN: &enableHTTP2} - userCopy := user.DeepCopy() - if userCopy.EnableHTTP2DSN == nil || *userCopy.EnableHTTP2DSN { - t.Fatalf("DeepCopy lost EnableHTTP2DSN: %v", userCopy.EnableHTTP2DSN) - } - *userCopy.EnableHTTP2DSN = true - if *user.EnableHTTP2DSN { - t.Error("DeepCopy aliased EnableHTTP2DSN pointer") - } if !cp.TokenCacheEnabled { t.Errorf("DeepCopy lost TokenCacheEnabled: %v", cp.TokenCacheEnabled) }