Skip to content

feat(c-abi): cooperative cancel token for blocking calls - #166

Closed
mani-mathur-arch wants to merge 1 commit into
mainfrom
mani/c-abi-cancel-token
Closed

mani-mathur-arch wants to merge 1 commit into
mainfrom
mani/c-abi-cancel-token

Conversation

@mani-mathur-arch

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

Copy link
Copy Markdown
Contributor

What

Add a cooperative cancel token to the kernel C ABI so a host (Go, ODBC) can interrupt an otherwise-uninterruptible blocking call by a caller deadline:

  • kernel_cancel_token_new / _cancel / _is_cancelled / _free — an opaque CancellationToken a host fires from a watcher thread.
  • kernel_session_open_cancellable (connect side) and kernel_result_stream_next_batch_cancellable (hung CloudFetch batch) — race the op against the token via a biased tokio::select!; a fire drops the in-flight future (a real reqwest abort) and yields Cancelled.

A NULL token routes to the identical plain-path behavior, so the default path and existing symbols are byte-for-byte unchanged. Additive only — ABI unchanged. tokio_util's CancellationToken is already a crate dep (no new cargo-deny entry).

Closes the runtime-contract gaps PECOBLR-3645 (mid-fetch cancel) and the connect half of PECOBLR-3646 (session-lifecycle deadlines). The token is protocol-neutral and reused verbatim by the OSS ODBC driver (shared C-ABI gap).

Stacked on #165 (mani/c-abi-pupr-statement-surface). Draft until #165 merges.

Tests

  • cancel.rs unit tests (lifecycle incl. the is_cancelled accessor, null guards).
  • Wiremock: pre-fired short-circuit, mid-connect cancel returns Cancelled in <5s against a 10s stalled server, NULL-token parity, and a direct next_batch_cancellable fetch-path test (pre-fired token short-circuits a real result stream; NULL token fetches normally).
  • C-smoke lifecycle + pre-fired short-circuit. make check green.

Co-authored-by: Isaac

@mani-mathur-arch
mani-mathur-arch changed the base branch from mani/c-abi-pupr-statement-surface to main July 19, 2026 08:57
@mani-mathur-arch
mani-mathur-arch force-pushed the mani/c-abi-cancel-token branch from e32c953 to 803734e Compare July 19, 2026 08:58
Add kernel_cancel_token_t plus cancellable variants of the connect and
result-fetch entry points, so a C-ABI host can interrupt an otherwise
uninterruptible blocking call by a caller deadline:

  - kernel_session_open_cancellable
  - kernel_result_stream_next_batch_cancellable

block_on_ffi_cancellable races the operation future against the token via a
biased tokio::select!; a fire drops the in-flight future, aborting the
underlying reqwest request (the crate's documented cancellation model), and
yields a typed Cancelled. A NULL token routes to the identical plain-path
behavior, so the default path and existing symbols are byte-for-byte
unchanged. Token firing is purely local (no RPC), safe to call from another
thread — modeled on the existing statement canceller. tokio_util's
CancellationToken is already a crate dependency, so no new cargo-deny entry.

Additive only — no existing symbol's layout or meaning changes, ABI unchanged.

Tests: cancel unit tests (incl. the is_cancelled accessor), wiremock
integration tests proving a mid-connect cancel returns Cancelled in under 5s
against a 10s stalled server (plus NULL-token parity and pre-fired
short-circuit), and C-smoke lifecycle + pre-fired short-circuit. make check
green.

Co-authored-by: Isaac
Signed-off-by: Mani Kaustubh Mathur <mani.mathur@databricks.com>
@mani-mathur-arch

Copy link
Copy Markdown
Contributor Author

not needed

This branch was previously deployed

1 inactive deployment
azure-prod — eb555541 Deployed Jul 19, 2026 by mani-mathur-arch via v0 E2E surface #218
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