Skip to content
15 changes: 15 additions & 0 deletions include/databricks_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,21 @@ KernelStatusCode kernel_statement_execute_with_timeout_ms(
KernelStatusCode kernel_statement_submit(kernel_statement_t* stmt,
kernel_executed_async_statement_t** out);

/* Submit-and-return with a client-side execution deadline in milliseconds.
* Zero selects unlimited execution; values above
* DATABRICKS_KERNEL_MAX_CLIENT_QUERY_TIMEOUT_MS return InvalidArgument. The
* deadline starts on entry and is retained by the returned async handle across
* status polls. If it expires before a terminal status is observed, status
* returns Timeout with SQLSTATE HYT00 and the kernel schedules best-effort
* cancel/close cleanup. One exception: if the deadline fires DURING the initial
* submit round-trip (before the server returns a statement id), no id is known
* yet, so no cancel/close can be scheduled; a statement the server may have
* created is left for session-close to reclaim. This window is small because
* submit uses wait_timeout=0s. Result fetching is outside this deadline. */
KernelStatusCode kernel_statement_submit_with_timeout_ms(
kernel_statement_t* stmt, uint64_t timeout_ms,
kernel_executed_async_statement_t** out);

/*
* Free the statement lifecycle owner. Does NOT free executed-handle
* boxes — each executed handle is a separate allocation that you must
Expand Down
38 changes: 35 additions & 3 deletions src/c_abi/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,33 @@ pub unsafe extern "C" fn kernel_executed_statement_close(
pub unsafe extern "C" fn kernel_statement_submit(
stmt: *mut kernel_statement_t,
out: *mut *mut kernel_executed_async_statement_t,
) -> KernelStatusCode {
submit_with_timeout(stmt, None, out)
}

/// Submit-and-return with a client-side deadline retained across status polls.
/// Zero means unlimited. Result materialisation/fetching is outside the
/// deadline, matching synchronous execution.
///
/// # Safety
/// `stmt` / `out` must be valid pointers.
#[no_mangle]
pub unsafe extern "C" fn kernel_statement_submit_with_timeout_ms(
stmt: *mut kernel_statement_t,
timeout_ms: u64,
out: *mut *mut kernel_executed_async_statement_t,
) -> KernelStatusCode {
submit_with_timeout(
stmt,
Some(std::time::Duration::from_millis(timeout_ms)),
out,
)
}

unsafe fn submit_with_timeout(
stmt: *mut kernel_statement_t,
timeout: Option<std::time::Duration>,
out: *mut *mut kernel_executed_async_statement_t,
) -> KernelStatusCode {
// Wrap the whole body in catch_ffi: block_on_ffi only catches a panic
// in the awaited future, so the surrounding sync prologue/epilogue
Expand All @@ -885,16 +912,21 @@ pub unsafe extern "C" fn kernel_statement_submit(
// thread-local error on entry.
catch_ffi(|| {
if out.is_null() {
return store_invalid_arg("kernel_statement_submit: out must not be null");
return store_invalid_arg("statement submit: out must not be null");
}
std::ptr::write(out, std::ptr::null_mut());
let Some(stmt) = statement_mut(stmt) else {
return store_invalid_arg("kernel_statement_submit: stmt must not be null");
return store_invalid_arg("statement submit: stmt must not be null");
};
let stmt_ptr: *mut Statement = stmt;
match block_on_ffi(move || {
let stmt = unsafe { &mut *stmt_ptr };
Box::pin(async move { stmt.submit().await })
Box::pin(async move {
match timeout {
Some(timeout) => stmt.submit_with_timeout(timeout).await,
None => stmt.submit().await,
}
})
}) {
Ok(exec) => {
let statement_id_c = crate::c_abi::error::to_cstring_lossy(exec.statement_id());
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@

//! Databricks SQL Kernel
//!
// `async_trait` marks its generated boxed futures as `must_use`. Rust 1.99's
// `double_must_use` lint also sees the `Future` trait's own annotation, so all
// async trait methods otherwise fail Clippy despite having the intended
// must-use behavior.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Low — This crate-level inner attribute suppresses clippy::double_must_use across the entire crate, not just the async_trait-generated methods the comment describes. The explanation is sound for the async-trait false positive, but a crate-wide blanket allow will also silence any genuine future double-#[must_use] on non-async-trait items. Consider scoping it more narrowly (e.g. on the trait definitions / modules that actually trip the lint) so legitimate occurrences elsewhere still surface. Non-blocking — the allow is documented and defensible given how pervasively async_trait is used here.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping the crate-level #![allow(clippy::double_must_use)] as-is (src/lib.rs:21). The double_must_use false positive is triggered by #[async_trait], which is applied to 18+ trait definitions spread across ~12 modules (src/config.rs, src/client/{sea,transport}.rs, src/statement/{handle,executed,executed_async}.rs, src/reader/** including mod.rs, inline/streaming.rs, cloudfetch/*, post_processor/mod.rs, src/metadata/thrift_shape.rs, src/telemetry/statement.rs). Scoping the allow per-trait/per-module would mean scattering the same attribute across all of those sites — a much larger and more fragile diff than the single documented crate-level allow, and it would have to be re-added each time a new async trait is introduced. The risk the comment flags (silencing a genuine future double-#[must_use]) is low: the crate has no legitimate double-must_use items today, and this is a Rust 1.99 lint interaction with async_trait's generated code rather than something we'd want to catch on our own items. Given the reviewer flagged this as Low/non-blocking and "defensible," I'm leaving the broad allow in place with its explanatory comment.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair points on the maintenance cost — scattering the attribute across 18+ async traits in a dozen modules, and re-adding it per new trait, is a real downside, and I agree the risk of masking a genuine double-#[must_use] is low today. Since no code change was made and the crate-wide allow remains in place, I'll leave this open rather than auto-resolve: it's a Low/non-blocking tradeoff that a human can close with a glance. If a future must_use item on a non-async-trait type ever does get silently swallowed, this thread is the breadcrumb back to the decision. No further action needed from your side.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛔ NEEDS HUMAN DECISION — the bots can't resolve this thread; a maintainer's input is required.

Thread has converged: reviewer flagged the crate-wide #![allow(clippy::double_must_use)] as Low/non-blocking, accepted the maintenance-cost rationale for not scoping it per-trait across 18+ async traits in ~12 modules, agreed the masking risk is low today, and explicitly stated no further action is needed — leaving it open deliberately as a breadcrumb for a human to close. No code change is warranted and no live question remains, so flagging for human close rather than continuing the exchange.

#![allow(clippy::double_must_use)]
//!
//! Rust client core for Databricks SQL — the shared engine that powers
//! the Databricks ODBC, Python, Go, and Node.js drivers.
//!
Expand Down
Loading
Loading