Repository navigation
fix(session): non-owning attached async handles + tighten http_error envelope - #147
Merged
Merged
Conversation
…ttp_error envelope Addresses review feedback on #139 (attach_async_statement). The attached handle was documented as a read-only adopt but still had paths that could tear down the statement its owner controls. P1 — attach must not tear down the owner's statement: - Add an `owning` flag to ExecutedAsyncStatement (true for submit, false for attach via the new `new_attached` constructor). - `await_result()` only arms the drop-cancel guard when `owning`. A non-owning handle whose await future is dropped mid-poll (e.g. a passive observer wrapping it in `tokio::time::timeout`) no longer fires `cancel_statement` against the owner's query. The owning submit path keeps the DBU-safety drop-cancel behaviour. - `ExecutedAsyncStatement::cancel()` and the derived `AsyncStatementCanceller::cancel()` error (InvalidArgument) on a non-owning handle instead of cancelling a statement the caller doesn't own. `owning` is inherited by the canceller so the footgun doesn't just move. P1 — http_error SQLSTATE validation: - Require the canonical 5-char SQLSTATE shape (`len() == 5`) before attaching it, matching `terminal_outcome` — was `!is_empty()`, which let junk like "X" through onto Error.sql_state. P2: - attach_async_statement stamps the statement id onto the NotFound error (with_query_id), matching terminal_outcome. - http_error parses the body once into serde_json::Value, then tries both envelope shapes off it (was two full string parses). - When the envelope has an error_code but no message, synthesize "server returned error_code <ec>" instead of folding the raw JSON body into the human-readable message. Tests: - attached_handle_await_result_drop_does_not_cancel_statement: a dropped await on an attached handle fires zero cancels (the owning await_result_drop_fires_cancel_statement pins the contrast). - attached_handle_cancel_errors: cancel() and the derived canceller both error on an attached handle, with zero cancels on the wire. Deferred (its own follow-up — needs a live system-table fixture to verify the exact server casing): list_table_types() advertises "SYSTEM TABLE" (space) while SHOW TABLES emits "SYSTEM_TABLE" (underscore); reconciling the canonical list is out of scope here. Co-authored-by: Isaac Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
gopalldb
approved these changes
Jun 8, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Follow-up to #139 addressing @gopalldb's review. #139's
attach_async_statementwas documented as a read-only adopt, but two paths could still tear down the statement its owner controls, and the newhttp_errorenvelope parsing was looser than the statement-level path.P1 — an attached handle must never tear down the owner's statement
owningflag toExecutedAsyncStatement—truefor the submitting handle (Statement::submit),falsefor attached handles (newnew_attachedconstructor used byattach_async_statement).await_result()only arms the drop-cancel guard whenowning. Before, a non-owning handle whose await future was dropped mid-poll (the canonicaltokio::time::timeoutpattern) would firecancel_statementagainst the owner's query. Now a passive observer can safelytimeout(attach(id).await_result())without cancelling someone else's statement. The owning submit path keeps its DBU-safety drop-cancel behaviour unchanged.cancel()errors on a non-owning handle (and so does the derivedAsyncStatementCanceller::cancel()—owningis inherited so the footgun doesn't just move to the detached canceller). ReturnsInvalidArgumentrather than firing a server-side cancel against a statement the caller doesn't own.P1 —
http_errorSQLSTATE validationlen() == 5) before attaching it, matchingsea.rs terminal_outcome. Was!is_empty(), which let junk ("X","garbage") ontoError.sql_state.P2
attach_async_statementstamps the statement id onto theNotFounderror (with_query_id), matchingterminal_outcome.http_errorparses the body once intoserde_json::Value, then tries both envelope shapes off it (was two full string parses).error_codebut nomessage, synthesize"server returned error_code <ec>"instead of folding the raw JSON body into the human-readable message.Testing
attached_handle_await_result_drop_does_not_cancel_statement— a dropped await on an attached handle fires zero cancels (the existingawait_result_drop_fires_cancel_statementpins the owning contrast).attached_handle_cancel_errors—cancel()and the derived canceller both error on an attached handle, with zero cancels on the wire.test_http_error_parses_sea_error_envelope/_falls_back_to_rawstill pass with the tightened SQLSTATE + single-parse changes.cargo +stable fmt --all,cargo clippy --all-targets -- -D warnings, fullcargo test— all green.Deferred (its own follow-up)
Review item:
list_table_types()advertises"SYSTEM TABLE"(space) whileSHOW TABLESemits"SYSTEM_TABLE"(underscore), so a round-trip of the canonical list intolist_tables(table_types=...)for system tables may not match. Reconciling the advertised list needs a live system-table fixture to confirm the exact server casing (a dogfood probe oversystem/samplessurfaced onlyTABLE/VIEW, no system-table row). Out of scope here — tracked as a separate investigation-first follow-up, as the reviewer suggested.