From e85d46ec07460a41add4542c530e22394180ce23 Mon Sep 17 00:00:00 2001 From: Vu Anh Phung Date: Tue, 25 Aug 2026 20:13:22 +0000 Subject: [PATCH 1/8] feat(kernel): forward request timeout Signed-off-by: Vu Anh Phung --- KERNEL_REV | 2 +- doc.go | 4 ++++ internal/backend/kernel/backend.go | 26 ++++++++++++++++++++++++++ internal/backend/kernel/config.go | 15 +++++++++++++++ internal/backend/kernel/config_test.go | 26 ++++++++++++++++++++++++++ internal/backend/kernel/kernel_test.go | 17 +++++++++++++++++ kernel_config.go | 2 ++ kernel_config_test.go | 3 +++ kernel_telemetry.go | 6 +++--- kernel_telemetry_test.go | 3 +++ 10 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 internal/backend/kernel/config_test.go diff --git a/KERNEL_REV b/KERNEL_REV index a7088393..f751c496 100644 --- a/KERNEL_REV +++ b/KERNEL_REV @@ -1 +1 @@ -e8d60c93b7459947d2e3e4113f62e6bda37fde8e +dd810d6d0a179886b923c6e22dc785ddca16ebef diff --git a/doc.go b/doc.go index 0dee82dd..b40148f2 100644 --- a/doc.go +++ b/doc.go @@ -226,6 +226,10 @@ static authenticators, and custom M2M OAuth scopes Unity Catalog volume) is rejected at execute. WithMaxRows is accepted but inert (the kernel manages fetching below the C ABI). +Kernel HTTP requests inherit the driver's 900s ClientTimeout. If that value is +zero, the kernel uses its own 120s default; zero is neither unlimited nor an +immediate timeout. + OAuth U2M is interactive: on a cache miss, connecting launches the system browser and blocks until login completes or the kernel's ~120s callback timeout expires. Because the C ABI can't interrupt session open mid-call, a connection-context deadline is not diff --git a/internal/backend/kernel/backend.go b/internal/backend/kernel/backend.go index df5c438b..e0300427 100644 --- a/internal/backend/kernel/backend.go +++ b/internal/backend/kernel/backend.go @@ -218,6 +218,10 @@ func (k *KernelBackend) OpenSession(ctx context.Context) error { return err } + if err := k.applyRequestTimeout(cfg); err != nil { + return err + } + // Retry / backoff policy (WithRetries). See applyRetry. if err := k.applyRetry(cfg); err != nil { return err @@ -357,6 +361,16 @@ func (k *KernelBackend) applyProxy(cfg *C.KernelSessionConfig) error { return nil } +func (k *KernelBackend) applyRequestTimeout(cfg *C.KernelSessionConfig) error { + timeoutMs := requestTimeoutMilliseconds(k.cfg.RequestTimeout) + if err := call(func() C.KernelStatusCode { + return C.kernel_session_config_set_request_timeout(cfg, C.uint64_t(timeoutMs)) + }); err != nil { + return fmt.Errorf("kernel: set_request_timeout: %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 @@ -541,6 +555,18 @@ func trySetTokenCacheConfig(auth Auth, enabled bool) error { return k.setAuth(cfg) } +// trySetRequestTimeout exercises the request-timeout C setter without opening a +// network session. It is used only by the tagged kernel tests. +func trySetRequestTimeout(cfg Config) error { + var c *C.KernelSessionConfig + if err := call(func() C.KernelStatusCode { return C.kernel_session_config_new(&c) }); err != nil { + return fmt.Errorf("config_new: %w", err) + } + defer C.kernel_session_config_free(c) + k := &KernelBackend{cfg: cfg} + return k.applyRequestTimeout(c) +} + // applyInitialNamespace runs USE CATALOG / USE SCHEMA to select the configured // initial namespace, since the kernel C ABI exposes no catalog/schema setter. // Identifiers are backtick-quoted (quoteIdent) so arbitrary names are safe. A diff --git a/internal/backend/kernel/config.go b/internal/backend/kernel/config.go index a77d5466..66beec48 100644 --- a/internal/backend/kernel/config.go +++ b/internal/backend/kernel/config.go @@ -21,6 +21,11 @@ type Config struct { // attributed to this driver (not the kernel's built-in UA). Empty leaves it unset. UserAgent string + // RequestTimeout is the total HTTP request deadline, from connect through + // response-body completion. Zero selects the kernel's 120s default; it is + // neither unlimited nor an immediate timeout. + RequestTimeout time.Duration + // SessionConf carries server-bound session confs verbatim — the same map the // Thrift backend forwards (STATEMENT_TIMEOUT, QUERY_TAGS, TIMEZONE, …). SessionConf map[string]string @@ -105,3 +110,13 @@ type RetryConfig struct { // default (900s). Mirrors the pyo3/napi retry_overall_timeout knob. OverallTimeout time.Duration } + +func requestTimeoutMilliseconds(timeout time.Duration) uint64 { + if timeout <= 0 { + return 0 + } + if timeout < time.Millisecond { + return 1 + } + return uint64(timeout.Milliseconds()) //nolint:gosec // timeout is positive and bounded by time.Duration +} diff --git a/internal/backend/kernel/config_test.go b/internal/backend/kernel/config_test.go new file mode 100644 index 00000000..70096721 --- /dev/null +++ b/internal/backend/kernel/config_test.go @@ -0,0 +1,26 @@ +package kernel + +import ( + "testing" + "time" +) + +func TestRequestTimeoutMilliseconds(t *testing.T) { + for _, tc := range []struct { + name string + timeout time.Duration + want uint64 + }{ + {"zero", 0, 0}, + {"negative", -time.Second, 0}, + {"sub-millisecond", time.Nanosecond, 1}, + {"fractional milliseconds", 1500 * time.Microsecond, 1}, + {"seconds", 12 * time.Second, 12_000}, + } { + t.Run(tc.name, func(t *testing.T) { + if got := requestTimeoutMilliseconds(tc.timeout); got != tc.want { + t.Errorf("requestTimeoutMilliseconds(%v) = %d, want %d", tc.timeout, got, tc.want) + } + }) + } +} diff --git a/internal/backend/kernel/kernel_test.go b/internal/backend/kernel/kernel_test.go index d49a8eab..75c084f6 100644 --- a/internal/backend/kernel/kernel_test.go +++ b/internal/backend/kernel/kernel_test.go @@ -170,6 +170,23 @@ func TestSetTokenCache(t *testing.T) { } } +func TestSetRequestTimeout(t *testing.T) { + for _, tc := range []struct { + name string + timeout time.Duration + }{ + {"default", 900 * time.Second}, + {"zero keeps kernel default", 0}, + {"sub-millisecond rounds up", time.Nanosecond}, + } { + t.Run(tc.name, func(t *testing.T) { + if err := trySetRequestTimeout(Config{RequestTimeout: tc.timeout}); err != nil { + t.Errorf("applyRequestTimeout(%s) = %v, want nil", tc.name, err) + } + }) + } +} + // TestKernelLogLevel and TestResolveKernelLogArg — the pure level-resolution tests — // live in the untagged logging_level_test.go so they run under CGO_ENABLED=0. The // tests below exercise klog/klogCtx and so need the cgo build. diff --git a/kernel_config.go b/kernel_config.go index 20d2b1f1..604b4af2 100644 --- a/kernel_config.go +++ b/kernel_config.go @@ -138,6 +138,8 @@ func buildKernelConfig(cfg *config.Config, kauth kernel.Auth) kernel.Config { WarehouseID: cfg.WarehouseID, Auth: kauth, Location: cfg.Location, + // ClientTimeout is the Go HTTP client's total request deadline. + RequestTimeout: cfg.ClientTimeout, // Same UA the Thrift path sends, so query history attributes both alike. UserAgent: client.BuildUserAgent(cfg), // Initial namespace: no kernel config setter, so the kernel backend applies diff --git a/kernel_config_test.go b/kernel_config_test.go index beca2c0c..107121bd 100644 --- a/kernel_config_test.go +++ b/kernel_config_test.go @@ -541,6 +541,9 @@ func TestBuildKernelConfig(t *testing.T) { if kc.Auth.Mode != kauth.Mode || kc.Auth.Token != kauth.Token { t.Errorf("auth not forwarded: got %+v, want %+v", kc.Auth, kauth) } + if kc.RequestTimeout != c.ClientTimeout { + t.Errorf("RequestTimeout = %v, want ClientTimeout %v", kc.RequestTimeout, c.ClientTimeout) + } // UserAgent must be the driver's composed UA, non-empty — else query // history mis-attributes SEA-path queries to the kernel's built-in UA. if want := client.BuildUserAgent(c); kc.UserAgent == "" || kc.UserAgent != want { diff --git a/kernel_telemetry.go b/kernel_telemetry.go index 390affd4..d83ca671 100644 --- a/kernel_telemetry.go +++ b/kernel_telemetry.go @@ -20,9 +20,8 @@ import ( // to actually emit it. Pure Go so it is unit-testable in the default build. // // It reports only what the kernel path genuinely applies: EnableArrow is always -// true (the kernel returns Arrow results), UseProxy reflects whether a proxy was -// resolved (env-var or WithKernelProxy), and it does not claim direct-results or a -// socket timeout the kernel C ABI has no knob for. +// true, UseProxy reflects the resolved proxy, and SocketTimeout reflects the same +// ClientTimeout forwarded to the kernel. It does not claim direct-results. func kernelConnectionTelemetry(cfg *config.Config) *telemetry.DriverConnectionParameters { params := &telemetry.DriverConnectionParameters{ HTTPPath: cfg.HTTPPath, @@ -40,6 +39,7 @@ func kernelConnectionTelemetry(cfg *config.Config) *telemetry.DriverConnectionPa }, UseProxy: kernelUsesProxy(cfg), EnableMetricViewMeta: cfg.EnableMetricViewMetadata, + SocketTimeout: cfg.ClientTimeout.Milliseconds(), } if qt := cfg.SessionParams["QUERY_TAGS"]; qt != "" { params.QueryTags = qt diff --git a/kernel_telemetry_test.go b/kernel_telemetry_test.go index 3bf3152d..d3b2fe97 100644 --- a/kernel_telemetry_test.go +++ b/kernel_telemetry_test.go @@ -43,6 +43,9 @@ func TestKernelConnectionTelemetry(t *testing.T) { if p.HostInfo == nil || p.HostInfo.HostURL != "example.cloud.databricks.com" || p.HostInfo.Port != 443 { t.Errorf("HostInfo = %+v, want host/port populated", p.HostInfo) } + if p.SocketTimeout != 900_000 { + t.Errorf("SocketTimeout = %d, want 900000", p.SocketTimeout) + } }) t.Run("query tags + metric-view are reflected", func(t *testing.T) { From 22ea4a4feb4b74338acc4a67805d3156aa7c3e32 Mon Sep 17 00:00:00 2001 From: Vu Anh Phung Date: Tue, 25 Aug 2026 20:34:38 +0000 Subject: [PATCH 2/8] fix(kernel): report effective request timeout Signed-off-by: Vu Anh Phung --- internal/backend/kernel/config.go | 13 +++++++++++-- internal/backend/kernel/config_test.go | 21 ++++++++++++++++++++- kernel_telemetry.go | 2 +- kernel_telemetry_test.go | 13 +++++++++++++ 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/internal/backend/kernel/config.go b/internal/backend/kernel/config.go index 66beec48..87a54177 100644 --- a/internal/backend/kernel/config.go +++ b/internal/backend/kernel/config.go @@ -111,12 +111,21 @@ type RetryConfig struct { OverallTimeout time.Duration } -func requestTimeoutMilliseconds(timeout time.Duration) uint64 { +func requestTimeoutMilliseconds(timeout time.Duration) int64 { if timeout <= 0 { return 0 } if timeout < time.Millisecond { return 1 } - return uint64(timeout.Milliseconds()) //nolint:gosec // timeout is positive and bounded by time.Duration + return timeout.Milliseconds() +} + +// EffectiveRequestTimeoutMilliseconds returns the deadline the kernel applies. +func EffectiveRequestTimeoutMilliseconds(timeout time.Duration) int64 { + timeoutMs := requestTimeoutMilliseconds(timeout) + if timeoutMs == 0 { + return 120_000 + } + return timeoutMs } diff --git a/internal/backend/kernel/config_test.go b/internal/backend/kernel/config_test.go index 70096721..995bd394 100644 --- a/internal/backend/kernel/config_test.go +++ b/internal/backend/kernel/config_test.go @@ -9,7 +9,7 @@ func TestRequestTimeoutMilliseconds(t *testing.T) { for _, tc := range []struct { name string timeout time.Duration - want uint64 + want int64 }{ {"zero", 0, 0}, {"negative", -time.Second, 0}, @@ -24,3 +24,22 @@ func TestRequestTimeoutMilliseconds(t *testing.T) { }) } } + +func TestEffectiveRequestTimeoutMilliseconds(t *testing.T) { + for _, tc := range []struct { + name string + timeout time.Duration + want int64 + }{ + {"zero uses kernel default", 0, 120_000}, + {"negative uses kernel default", -time.Second, 120_000}, + {"sub-millisecond", time.Nanosecond, 1}, + {"seconds", 12 * time.Second, 12_000}, + } { + t.Run(tc.name, func(t *testing.T) { + if got := EffectiveRequestTimeoutMilliseconds(tc.timeout); got != tc.want { + t.Errorf("EffectiveRequestTimeoutMilliseconds(%v) = %d, want %d", tc.timeout, got, tc.want) + } + }) + } +} diff --git a/kernel_telemetry.go b/kernel_telemetry.go index d83ca671..b237c94c 100644 --- a/kernel_telemetry.go +++ b/kernel_telemetry.go @@ -39,7 +39,7 @@ func kernelConnectionTelemetry(cfg *config.Config) *telemetry.DriverConnectionPa }, UseProxy: kernelUsesProxy(cfg), EnableMetricViewMeta: cfg.EnableMetricViewMetadata, - SocketTimeout: cfg.ClientTimeout.Milliseconds(), + SocketTimeout: kernel.EffectiveRequestTimeoutMilliseconds(cfg.ClientTimeout), } if qt := cfg.SessionParams["QUERY_TAGS"]; qt != "" { params.QueryTags = qt diff --git a/kernel_telemetry_test.go b/kernel_telemetry_test.go index d3b2fe97..c16a2421 100644 --- a/kernel_telemetry_test.go +++ b/kernel_telemetry_test.go @@ -63,6 +63,19 @@ func TestKernelConnectionTelemetry(t *testing.T) { } }) + t.Run("request timeout reports the effective kernel value", func(t *testing.T) { + cfg := config.WithDefaults() + cfg.ClientTimeout = 0 + if got := kernelConnectionTelemetry(cfg).SocketTimeout; got != 120_000 { + t.Errorf("SocketTimeout = %d, want kernel default 120000", got) + } + + cfg.ClientTimeout = time.Nanosecond + if got := kernelConnectionTelemetry(cfg).SocketTimeout; got != 1 { + t.Errorf("SocketTimeout = %d, want rounded-up 1", got) + } + }) + t.Run("explicit WithKernelProxy marks UseProxy", func(t *testing.T) { cfg := config.WithDefaults() cfg.AccessToken = "dapi-x" From 58f48d4d4cae57e42238b808bc933eb40dfa86e5 Mon Sep 17 00:00:00 2001 From: Vu Anh Phung Date: Tue, 25 Aug 2026 20:46:32 +0000 Subject: [PATCH 3/8] docs(kernel): clarify request timeout default Signed-off-by: Vu Anh Phung --- doc.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc.go b/doc.go index b40148f2..297618b7 100644 --- a/doc.go +++ b/doc.go @@ -226,9 +226,9 @@ static authenticators, and custom M2M OAuth scopes Unity Catalog volume) is rejected at execute. WithMaxRows is accepted but inert (the kernel manages fetching below the C ABI). -Kernel HTTP requests inherit the driver's 900s ClientTimeout. If that value is -zero, the kernel uses its own 120s default; zero is neither unlimited nor an -immediate timeout. +Kernel HTTP requests inherit the driver's ClientTimeout (900s by default). If +that value is zero, the kernel uses its own 120s default; zero is neither +unlimited nor an immediate timeout. OAuth U2M is interactive: on a cache miss, connecting launches the system browser and blocks until login completes or the kernel's ~120s callback timeout expires. Because From 2be7e4a53e50c03f6f9c9b168687286562dfd665 Mon Sep 17 00:00:00 2001 From: Vu Anh Phung Date: Tue, 25 Aug 2026 21:08:18 +0000 Subject: [PATCH 4/8] fix(kernel): report encoded request timeout Signed-off-by: Vu Anh Phung --- internal/backend/kernel/backend.go | 2 +- internal/backend/kernel/config.go | 13 +++---------- internal/backend/kernel/config_test.go | 23 ++--------------------- kernel_telemetry.go | 4 ++-- kernel_telemetry_test.go | 6 +++--- 5 files changed, 11 insertions(+), 37 deletions(-) diff --git a/internal/backend/kernel/backend.go b/internal/backend/kernel/backend.go index e0300427..2b24abd3 100644 --- a/internal/backend/kernel/backend.go +++ b/internal/backend/kernel/backend.go @@ -362,7 +362,7 @@ func (k *KernelBackend) applyProxy(cfg *C.KernelSessionConfig) error { } func (k *KernelBackend) applyRequestTimeout(cfg *C.KernelSessionConfig) error { - timeoutMs := requestTimeoutMilliseconds(k.cfg.RequestTimeout) + timeoutMs := RequestTimeoutMilliseconds(k.cfg.RequestTimeout) if err := call(func() C.KernelStatusCode { return C.kernel_session_config_set_request_timeout(cfg, C.uint64_t(timeoutMs)) }); err != nil { diff --git a/internal/backend/kernel/config.go b/internal/backend/kernel/config.go index 87a54177..9d7b6b15 100644 --- a/internal/backend/kernel/config.go +++ b/internal/backend/kernel/config.go @@ -111,7 +111,9 @@ type RetryConfig struct { OverallTimeout time.Duration } -func requestTimeoutMilliseconds(timeout time.Duration) int64 { +// RequestTimeoutMilliseconds returns the value sent to the C ABI. Zero selects +// the kernel default; positive sub-millisecond values round up to 1ms. +func RequestTimeoutMilliseconds(timeout time.Duration) int64 { if timeout <= 0 { return 0 } @@ -120,12 +122,3 @@ func requestTimeoutMilliseconds(timeout time.Duration) int64 { } return timeout.Milliseconds() } - -// EffectiveRequestTimeoutMilliseconds returns the deadline the kernel applies. -func EffectiveRequestTimeoutMilliseconds(timeout time.Duration) int64 { - timeoutMs := requestTimeoutMilliseconds(timeout) - if timeoutMs == 0 { - return 120_000 - } - return timeoutMs -} diff --git a/internal/backend/kernel/config_test.go b/internal/backend/kernel/config_test.go index 995bd394..430827dd 100644 --- a/internal/backend/kernel/config_test.go +++ b/internal/backend/kernel/config_test.go @@ -18,27 +18,8 @@ func TestRequestTimeoutMilliseconds(t *testing.T) { {"seconds", 12 * time.Second, 12_000}, } { t.Run(tc.name, func(t *testing.T) { - if got := requestTimeoutMilliseconds(tc.timeout); got != tc.want { - t.Errorf("requestTimeoutMilliseconds(%v) = %d, want %d", tc.timeout, got, tc.want) - } - }) - } -} - -func TestEffectiveRequestTimeoutMilliseconds(t *testing.T) { - for _, tc := range []struct { - name string - timeout time.Duration - want int64 - }{ - {"zero uses kernel default", 0, 120_000}, - {"negative uses kernel default", -time.Second, 120_000}, - {"sub-millisecond", time.Nanosecond, 1}, - {"seconds", 12 * time.Second, 12_000}, - } { - t.Run(tc.name, func(t *testing.T) { - if got := EffectiveRequestTimeoutMilliseconds(tc.timeout); got != tc.want { - t.Errorf("EffectiveRequestTimeoutMilliseconds(%v) = %d, want %d", tc.timeout, got, tc.want) + if got := RequestTimeoutMilliseconds(tc.timeout); got != tc.want { + t.Errorf("RequestTimeoutMilliseconds(%v) = %d, want %d", tc.timeout, got, tc.want) } }) } diff --git a/kernel_telemetry.go b/kernel_telemetry.go index b237c94c..60ad37c6 100644 --- a/kernel_telemetry.go +++ b/kernel_telemetry.go @@ -21,7 +21,7 @@ import ( // // It reports only what the kernel path genuinely applies: EnableArrow is always // true, UseProxy reflects the resolved proxy, and SocketTimeout reflects the same -// ClientTimeout forwarded to the kernel. It does not claim direct-results. +// encoded timeout sent to the kernel C ABI. It does not claim direct-results. func kernelConnectionTelemetry(cfg *config.Config) *telemetry.DriverConnectionParameters { params := &telemetry.DriverConnectionParameters{ HTTPPath: cfg.HTTPPath, @@ -39,7 +39,7 @@ func kernelConnectionTelemetry(cfg *config.Config) *telemetry.DriverConnectionPa }, UseProxy: kernelUsesProxy(cfg), EnableMetricViewMeta: cfg.EnableMetricViewMetadata, - SocketTimeout: kernel.EffectiveRequestTimeoutMilliseconds(cfg.ClientTimeout), + SocketTimeout: kernel.RequestTimeoutMilliseconds(cfg.ClientTimeout), } if qt := cfg.SessionParams["QUERY_TAGS"]; qt != "" { params.QueryTags = qt diff --git a/kernel_telemetry_test.go b/kernel_telemetry_test.go index c16a2421..24a9adcb 100644 --- a/kernel_telemetry_test.go +++ b/kernel_telemetry_test.go @@ -63,11 +63,11 @@ func TestKernelConnectionTelemetry(t *testing.T) { } }) - t.Run("request timeout reports the effective kernel value", func(t *testing.T) { + t.Run("request timeout reports the C ABI value", func(t *testing.T) { cfg := config.WithDefaults() cfg.ClientTimeout = 0 - if got := kernelConnectionTelemetry(cfg).SocketTimeout; got != 120_000 { - t.Errorf("SocketTimeout = %d, want kernel default 120000", got) + if got := kernelConnectionTelemetry(cfg).SocketTimeout; got != 0 { + t.Errorf("SocketTimeout = %d, want 0 (use kernel default)", got) } cfg.ClientTimeout = time.Nanosecond From 5c0f23d7c75958c37b24cdff06dbe42a89e76edb Mon Sep 17 00:00:00 2001 From: Vu Anh Phung Date: Tue, 25 Aug 2026 21:31:04 +0000 Subject: [PATCH 5/8] fix(telemetry): report socket timeout in seconds Signed-off-by: Vu Anh Phung --- internal/backend/kernel/backend.go | 2 +- internal/backend/kernel/config.go | 4 ++-- internal/backend/kernel/config_test.go | 4 ++-- kernel_telemetry.go | 20 ++++++++++++++--- kernel_telemetry_test.go | 31 +++++++++++++++++--------- 5 files changed, 42 insertions(+), 19 deletions(-) diff --git a/internal/backend/kernel/backend.go b/internal/backend/kernel/backend.go index 2b24abd3..e0300427 100644 --- a/internal/backend/kernel/backend.go +++ b/internal/backend/kernel/backend.go @@ -362,7 +362,7 @@ func (k *KernelBackend) applyProxy(cfg *C.KernelSessionConfig) error { } func (k *KernelBackend) applyRequestTimeout(cfg *C.KernelSessionConfig) error { - timeoutMs := RequestTimeoutMilliseconds(k.cfg.RequestTimeout) + timeoutMs := requestTimeoutMilliseconds(k.cfg.RequestTimeout) if err := call(func() C.KernelStatusCode { return C.kernel_session_config_set_request_timeout(cfg, C.uint64_t(timeoutMs)) }); err != nil { diff --git a/internal/backend/kernel/config.go b/internal/backend/kernel/config.go index 9d7b6b15..81e2c47e 100644 --- a/internal/backend/kernel/config.go +++ b/internal/backend/kernel/config.go @@ -111,9 +111,9 @@ type RetryConfig struct { OverallTimeout time.Duration } -// RequestTimeoutMilliseconds returns the value sent to the C ABI. Zero selects +// requestTimeoutMilliseconds returns the value sent to the C ABI. Zero selects // the kernel default; positive sub-millisecond values round up to 1ms. -func RequestTimeoutMilliseconds(timeout time.Duration) int64 { +func requestTimeoutMilliseconds(timeout time.Duration) int64 { if timeout <= 0 { return 0 } diff --git a/internal/backend/kernel/config_test.go b/internal/backend/kernel/config_test.go index 430827dd..e1433182 100644 --- a/internal/backend/kernel/config_test.go +++ b/internal/backend/kernel/config_test.go @@ -18,8 +18,8 @@ func TestRequestTimeoutMilliseconds(t *testing.T) { {"seconds", 12 * time.Second, 12_000}, } { t.Run(tc.name, func(t *testing.T) { - if got := RequestTimeoutMilliseconds(tc.timeout); got != tc.want { - t.Errorf("RequestTimeoutMilliseconds(%v) = %d, want %d", tc.timeout, got, tc.want) + if got := requestTimeoutMilliseconds(tc.timeout); got != tc.want { + t.Errorf("requestTimeoutMilliseconds(%v) = %d, want %d", tc.timeout, got, tc.want) } }) } diff --git a/kernel_telemetry.go b/kernel_telemetry.go index 60ad37c6..2a65f01a 100644 --- a/kernel_telemetry.go +++ b/kernel_telemetry.go @@ -1,6 +1,8 @@ package dbsql import ( + "time" + "github.com/databricks/databricks-sql-go/internal/backend/kernel" "github.com/databricks/databricks-sql-go/internal/config" "github.com/databricks/databricks-sql-go/telemetry" @@ -20,8 +22,9 @@ import ( // to actually emit it. Pure Go so it is unit-testable in the default build. // // It reports only what the kernel path genuinely applies: EnableArrow is always -// true, UseProxy reflects the resolved proxy, and SocketTimeout reflects the same -// encoded timeout sent to the kernel C ABI. It does not claim direct-results. +// true, UseProxy reflects the resolved proxy, and SocketTimeout reports the +// configured ClientTimeout in the receiver schema's seconds unit. It does not +// claim direct-results. func kernelConnectionTelemetry(cfg *config.Config) *telemetry.DriverConnectionParameters { params := &telemetry.DriverConnectionParameters{ HTTPPath: cfg.HTTPPath, @@ -39,7 +42,7 @@ func kernelConnectionTelemetry(cfg *config.Config) *telemetry.DriverConnectionPa }, UseProxy: kernelUsesProxy(cfg), EnableMetricViewMeta: cfg.EnableMetricViewMetadata, - SocketTimeout: kernel.RequestTimeoutMilliseconds(cfg.ClientTimeout), + SocketTimeout: kernelSocketTimeoutSeconds(cfg.ClientTimeout), } if qt := cfg.SessionParams["QUERY_TAGS"]; qt != "" { params.QueryTags = qt @@ -67,6 +70,17 @@ func kernelConnectionTelemetry(cfg *config.Config) *telemetry.DriverConnectionPa return params } +func kernelSocketTimeoutSeconds(timeout time.Duration) int64 { + if timeout <= 0 { + return 0 + } + seconds := timeout / time.Second + if timeout%time.Second >= time.Second/2 { + seconds++ + } + return int64(seconds) +} + // kernelUsesProxy reports whether the kernel connection will route through a // proxy: either an explicit WithKernelProxy or an environment-resolved one for // this endpoint. Mirrors resolveKernelProxy's proxy-source precedence. diff --git a/kernel_telemetry_test.go b/kernel_telemetry_test.go index 24a9adcb..75b98b62 100644 --- a/kernel_telemetry_test.go +++ b/kernel_telemetry_test.go @@ -43,8 +43,8 @@ func TestKernelConnectionTelemetry(t *testing.T) { if p.HostInfo == nil || p.HostInfo.HostURL != "example.cloud.databricks.com" || p.HostInfo.Port != 443 { t.Errorf("HostInfo = %+v, want host/port populated", p.HostInfo) } - if p.SocketTimeout != 900_000 { - t.Errorf("SocketTimeout = %d, want 900000", p.SocketTimeout) + if p.SocketTimeout != 900 { + t.Errorf("SocketTimeout = %d, want 900", p.SocketTimeout) } }) @@ -63,16 +63,25 @@ func TestKernelConnectionTelemetry(t *testing.T) { } }) - t.Run("request timeout reports the C ABI value", func(t *testing.T) { + t.Run("request timeout reports receiver-schema seconds", func(t *testing.T) { cfg := config.WithDefaults() - cfg.ClientTimeout = 0 - if got := kernelConnectionTelemetry(cfg).SocketTimeout; got != 0 { - t.Errorf("SocketTimeout = %d, want 0 (use kernel default)", got) - } - - cfg.ClientTimeout = time.Nanosecond - if got := kernelConnectionTelemetry(cfg).SocketTimeout; got != 1 { - t.Errorf("SocketTimeout = %d, want rounded-up 1", got) + for _, tc := range []struct { + name string + timeout time.Duration + want int64 + }{ + {"zero", 0, 0}, + {"negative", -time.Second, 0}, + {"fractional second rounds down", 1499 * time.Millisecond, 1}, + {"half second rounds up", 1500 * time.Millisecond, 2}, + {"whole seconds", 12 * time.Second, 12}, + } { + t.Run(tc.name, func(t *testing.T) { + cfg.ClientTimeout = tc.timeout + if got := kernelConnectionTelemetry(cfg).SocketTimeout; got != tc.want { + t.Errorf("SocketTimeout = %d, want %d", got, tc.want) + } + }) } }) From 56c3837da878dcc05eb3189c7c683cdf94930ee1 Mon Sep 17 00:00:00 2001 From: Vu Anh Phung Date: Tue, 25 Aug 2026 21:49:16 +0000 Subject: [PATCH 6/8] fix(telemetry): preserve positive timeout sentinel Signed-off-by: Vu Anh Phung --- kernel_telemetry.go | 3 +++ kernel_telemetry_test.go | 1 + 2 files changed, 4 insertions(+) diff --git a/kernel_telemetry.go b/kernel_telemetry.go index 2a65f01a..485402b1 100644 --- a/kernel_telemetry.go +++ b/kernel_telemetry.go @@ -78,6 +78,9 @@ func kernelSocketTimeoutSeconds(timeout time.Duration) int64 { if timeout%time.Second >= time.Second/2 { seconds++ } + if seconds == 0 { + return 1 + } return int64(seconds) } diff --git a/kernel_telemetry_test.go b/kernel_telemetry_test.go index 75b98b62..dc1f5b3b 100644 --- a/kernel_telemetry_test.go +++ b/kernel_telemetry_test.go @@ -72,6 +72,7 @@ func TestKernelConnectionTelemetry(t *testing.T) { }{ {"zero", 0, 0}, {"negative", -time.Second, 0}, + {"positive sub-second floors to one", time.Nanosecond, 1}, {"fractional second rounds down", 1499 * time.Millisecond, 1}, {"half second rounds up", 1500 * time.Millisecond, 2}, {"whole seconds", 12 * time.Second, 12}, From 6abc305563038c4fed24de81953dff06220a0a87 Mon Sep 17 00:00:00 2001 From: Vu Anh Phung Date: Wed, 26 Aug 2026 05:01:27 +0000 Subject: [PATCH 7/8] docs(kernel): document request timeout forwarding Signed-off-by: Vu Anh Phung --- CONNECTION_PARAMETERS.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CONNECTION_PARAMETERS.md b/CONNECTION_PARAMETERS.md index a1e5102d..a3131a8e 100644 --- a/CONNECTION_PARAMETERS.md +++ b/CONNECTION_PARAMETERS.md @@ -95,6 +95,11 @@ Notes for the SEA/kernel backend: | `timezone` | `WithSessionParams(timezone=…)` | ✅ | ✅ | | Session time zone (e.g. `America/Los_Angeles`). | | `enableMetricViewMetadata` | `WithEnableMetricViewMetadata` | ✅ | ⚠️ | `false` | Enables metric-view metadata (sets `spark.sql.thriftserver.metadata.metricview.enabled=true`). Both paths forward the **identical** conf; the kernel allowlists this key and sends it verbatim — it is **not** rejected driver- or kernel-side. Whether it takes effect on the SEA/kernel path depends on server-side SEA support (a `⚠️` pending confirmation against a live warehouse; PECOBLR-4142 / PECOBLR-4153). | +**Kernel request timeout.** Kernel HTTP requests inherit the driver's internal +`ClientTimeout` (900s by default). A zero value keeps the kernel's 120s default; +it does not disable the timeout or cause an immediate timeout. `ClientTimeout` +is not currently exposed as a DSN parameter or `WithX` connector option. + ### Kernel session-conf allowlist On the **Thrift** path the `WithSessionParams` map is forwarded to the server freely. From 54d77569e2eae0e0a2f2999361199603cf90a356 Mon Sep 17 00:00:00 2001 From: Vu Anh Phung Date: Wed, 26 Aug 2026 16:10:56 +0000 Subject: [PATCH 8/8] docs: omit internal client timeout Signed-off-by: Vu Anh Phung --- CONNECTION_PARAMETERS.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/CONNECTION_PARAMETERS.md b/CONNECTION_PARAMETERS.md index a3131a8e..a1e5102d 100644 --- a/CONNECTION_PARAMETERS.md +++ b/CONNECTION_PARAMETERS.md @@ -95,11 +95,6 @@ Notes for the SEA/kernel backend: | `timezone` | `WithSessionParams(timezone=…)` | ✅ | ✅ | | Session time zone (e.g. `America/Los_Angeles`). | | `enableMetricViewMetadata` | `WithEnableMetricViewMetadata` | ✅ | ⚠️ | `false` | Enables metric-view metadata (sets `spark.sql.thriftserver.metadata.metricview.enabled=true`). Both paths forward the **identical** conf; the kernel allowlists this key and sends it verbatim — it is **not** rejected driver- or kernel-side. Whether it takes effect on the SEA/kernel path depends on server-side SEA support (a `⚠️` pending confirmation against a live warehouse; PECOBLR-4142 / PECOBLR-4153). | -**Kernel request timeout.** Kernel HTTP requests inherit the driver's internal -`ClientTimeout` (900s by default). A zero value keeps the kernel's 120s default; -it does not disable the timeout or cause an immediate timeout. `ClientTimeout` -is not currently exposed as a DSN parameter or `WithX` connector option. - ### Kernel session-conf allowlist On the **Thrift** path the `WithSessionParams` map is forwarded to the server freely.