Skip to content

feat(kernel): honor ctx deadlines on connect and mid-fetch#409

Draft
mani-mathur-arch wants to merge 2 commits into
mani/sea-kernel-consolidatedfrom
mani/sea-kernel-ctx-cancel
Draft

feat(kernel): honor ctx deadlines on connect and mid-fetch#409
mani-mathur-arch wants to merge 2 commits into
mani/sea-kernel-consolidatedfrom
mani/sea-kernel-ctx-cancel

Conversation

@mani-mathur-arch

@mani-mathur-arch mani-mathur-arch commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

What

Wire the kernel backend's two blocking cgo calls to the new cancellable C-ABI entry points via a ctxWatcher that bridges a Go context onto a kernel cancel token:

  • OpenSessionkernel_session_open_cancellable (connect)
  • rows.go nextBatchkernel_result_stream_next_batch_cancellable (mid-fetch)

Previously each blocked in an uninterruptible cgo call: a slow warehouse cold-start or a hung CloudFetch chunk ignored the caller's ctx deadline. The watcher fires the token on ctx.Done(), dropping the in-flight kernel request future (a real abort); the call sites prefer the ctx error while preserving the kernel error as cause, and evict a session-fatal conn before the ctx-cancelled return. A non-cancellable ctx yields a nil watcher → NULL token → the plain, unchanged path (zero overhead). CloseSession stays fire-and-forget.

Closes PECOBLR-3645 + the connect half of PECOBLR-3646.

Stacked on #399 (mani/sea-kernel-consolidated). Draft — CI build is red until KERNEL_REV is bumped to a merged kernel SHA carrying the cancellable symbols (it links a locally-staged archive today).

Tests

  • Tagged ctxWatcher unit tests (fires on cancel/deadline, nil-safe on an uncancellable ctx, clean teardown) exercising the real cgo ctx→token bridge in the build-and-test-kernel CI job.
  • Staging e2e: connect under an already-cancelled ctx fails fast; a long streaming query past its deadline is cancelled promptly with context.DeadlineExceeded. Default CGO_ENABLED=0 build unchanged.

Co-authored-by: Isaac

Wire the kernel backend's two blocking cgo calls to the new cancellable
C-ABI entry points via a ctxWatcher that bridges a Go context onto a kernel
cancel token:

  - OpenSession -> kernel_session_open_cancellable
  - rows.go nextBatch -> kernel_result_stream_next_batch_cancellable

Previously each blocked in an uninterruptible cgo call: a slow warehouse
cold-start or a hung CloudFetch chunk ignored the caller's ctx deadline. The
watcher fires the token on ctx.Done(), which drops the in-flight kernel request
future (a real abort), and the call sites prefer the ctx error on cancellation
while preserving the kernel error as cause (matching the execute path and the
database/sql convention). A session-fatal error is evicted before the
ctx-cancelled return so a failure racing a cancel still evicts the conn. A
non-cancellable ctx (nil Done) yields a nil watcher -> NULL token -> the plain,
unchanged path, so there is zero watcher overhead on the common case.

Requires the kernel cancel-token symbols; bump KERNEL_REV to the merged kernel
revision before this builds in CI (it links a locally-staged archive today).

Tests: tagged ctxWatcher unit tests (fires on cancel/deadline, nil-safe on an
uncancellable ctx, clean teardown without fire) exercising the real cgo
ctx->token bridge in the build-and-test-kernel CI job. Default CGO_ENABLED=0
build unchanged.

Co-authored-by: Isaac
Signed-off-by: Mani Kaustubh Mathur <mani.mathur@databricks.com>
Bumps the kernel pin from the placeholder statement-surface rev to the tip of
the tier2-features branch (databricks-sql-kernel#167 @ 02c0a43), the head of the
unmerged kernel PR stack (#165 -> #166 cancel-token -> #167 tier2). It's a linear
superset carrying every new C-ABI symbol these driver branches link against:
kernel_session_open_cancellable / kernel_result_stream_next_batch_cancellable
(cancel token, #166) plus kernel_abi_version, kernel_session_close_blocking,
set_tls_client_certificate, set_cloudfetch_enabled (#167). The kernel-lib build
fetches the bare commit via its PR-head-ref fallback, so an unmerged SHA is
buildable. Temporary: re-pin to the squash-merge SHA once the kernel stack lands.

Co-authored-by: Isaac
Signed-off-by: Mani Kaustubh Mathur <mani.mathur@databricks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant