Repository navigation
fix(statement): skip redundant CloseStatement for CLOSED async results; cover inline sync path (#168) - #222
Merged
Conversation
…OSED (#168) Issue #168 (extended by conformance cell CLOUDFETCH-013) reported that a regular inline query (`SELECT 1` delivered via direct results with `status.state == CLOSED`) might still emit a redundant `DELETE /api/2.0/sql/statements/<id>` (CloseStatement) on `ExecutedStatement::close()` / drop, the same way the metadata path did before PR #183. The regular-query path is in fact already correct: `Statement::execute` computes `already_closed = result.status.state == StatementState::Closed` (since PR #140) and pre-seeds the shared `closed` flag, so neither the drain auto-close, the explicit `close()`, nor `Drop` fires the redundant DELETE. But there was no dedicated regression test asserting the wire behavior on this path — only implicit coverage. Add two wiremock regression tests mirroring the metadata suite: - `execute_closed_inline_skips_close_statement` — a CLOSED inline `SELECT 1`, drained and explicitly closed, must produce ZERO DELETEs on the statement endpoint (expect(0) scoped mock + polled received_requests). - `execute_succeeded_inline_still_closes_statement` — a SUCCEEDED inline result must STILL fire exactly one CloseStatement, guarding against the skip over-correcting into a server-statement leak. The CLOSED-skip test is a verified tripwire: temporarily forcing `already_closed = false` makes it fail with one observed DELETE, and it passes on the real code. Co-authored-by: Isaac Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
vikrantpuppala
temporarily deployed
to
azure-prod
August 10, 2026 05:32 — with
GitHub Actions
Inactive
vikrantpuppala
temporarily deployed
to
azure-prod
August 10, 2026 05:32 — with
GitHub Actions
Inactive
vikrantpuppala
temporarily deployed
to
azure-prod
August 10, 2026 05:32 — with
GitHub Actions
Inactive
…OSED (#168) The async path (`Statement::submit` → `ExecutedAsyncStatement`) had the same redundant-CloseStatement bug that #183 fixed for metadata and that the sync `execute()` path already avoids: when the statement auto-closes server-side and a poll observes `status.state == CLOSED`, the handle never flipped its shared `closed` flag, so `close()` / `Drop` (and `invalidate_prior` on the parent `Statement`'s next execute) fired a redundant `DELETE /api/2.0/sql/statements/<id>` on an already-closed statement (server responds 404 STATEMENT_NOT_FOUND). The submit response itself uses `wait_timeout=0s` and can't return CLOSED, so `closed` correctly starts `false`; the gap was that reaching CLOSED via a later `await_result()` / `fetch_result()` poll never updated it. Fix in `materialise_result` — the common sink for both `await_result` and `fetch_result` — pre-set `closed = true` when the fetched result's terminal status is `CLOSED`, mirroring the sync path's `already_closed` short-circuit. `SUCCEEDED` is unchanged: the server still owns the statement, so exactly one CloseStatement still fires. Tests (tests/v0_async_execute_wiremock.rs): - `await_result_closed_status_skips_close_statement` — CLOSED async result, drained + explicitly closed, must fire ZERO DELETEs. Verified tripwire: fails with one observed DELETE before the fix. - `await_result_succeeded_status_still_closes_statement` — SUCCEEDED async result must STILL fire exactly one CloseStatement (no over-correction). Co-authored-by: Isaac Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
vikrantpuppala
temporarily deployed
to
azure-prod
August 10, 2026 05:39 — with
GitHub Actions
Inactive
vikrantpuppala
temporarily deployed
to
azure-prod
August 10, 2026 05:39 — with
GitHub Actions
Inactive
vikrantpuppala
temporarily deployed
to
azure-prod
August 10, 2026 05:39 — with
GitHub Actions
Inactive
vikrantpuppala
temporarily deployed
to
azure-prod
August 10, 2026 05:39 — with
GitHub Actions
Inactive
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.
Summary
Follow-up to #168 and PR #183. The original issue's metadata-path bug (redundant
CloseStatementDELETE on a statement whoseExecuteStatementresponse already reportedstate=CLOSED) was fixed in #183. Investigating the two extensions raised later in the thread, I found:Statement::executecomputesalready_closed = result.status.state == StatementState::Closed(since feat(statement): add directResults execute_direct (additive); CLOSED as terminal success #140) and pre-seeds the sharedclosedflag, so the drain auto-close, explicitclose(), andDropall short-circuit — no redundant DELETE. There was just no dedicated regression test on the wire.Statement::submit→ExecutedAsyncStatement): genuinely broken — same bug pattern, now fixed. The submit response useswait_timeout=0sand can't return CLOSED, soclosedcorrectly startsfalse; but reaching CLOSED via a laterawait_result()/fetch_result()poll never flipped it, soclose()/Drop(andinvalidate_prioron the next execute) fired a redundant DELETE on an already-closed statement.Changes
Fix (
src/statement/executed_async.rs): inmaterialise_result— the common sink for bothawait_resultandfetch_result— pre-setclosed = truewhen the fetched result's terminal status isCLOSED, mirroring the sync path'salready_closedshort-circuit.SUCCEEDEDis unchanged (server still owns the statement → one CloseStatement still fires).Tests:
tests/v0_async_execute_wiremock.rsawait_result_closed_status_skips_close_statement— verified tripwire: fails with one observed DELETE before the fix, passes after.await_result_succeeded_status_still_closes_statement— guards against over-correcting into a leak.tests/v0_execute_wiremock.rs(regression coverage for the already-correct sync path)execute_closed_inline_skips_close_statement— verified tripwire (fails ifalready_closedis forced tofalse).execute_succeeded_inline_still_closes_statement.Sibling-path audit (issue #168 pattern)
StatementCloseGuard)execute()already_closed); now tested hereexecute_direct()already_closedline)submit+await_result/fetch_resultOn the async-close race (axis #1 in the thread)
The thread also raised that the close is a detached
runtime.spawn, so the DELETE for a prior statement can race the nextExecuteStatementon a re-execute loop. I deliberately did not change this: it is not a correctness bug (the DELETE targets the prior, already-terminal statement; the next POST creates a fresh independent one —close_statementis scoped to a specific id and can't affect the new statement or session), it only occurs for non-CLOSED statements, and the fire-and-forget close is a deliberate, measured perf optimization (#85: removedCancel → Closefrom the critical path, ~10-14% wall-clock win on large-result re-execute loops). The reported proxy-replay non-determinism was already handled downstream with a per-test connection. With this PR the common CLOSED case spawns no close at all, so there is nothing to race there.Test plan
cargo test— 737 lib tests + all integration suites, 0 failurescargo clippy --all-targets -- -D warnings— cleancargo +stable fmt --all*_closed_*tests verified as tripwires (fail before the respective fix, pass after)Closes #168
Closes #188
This pull request and its description were written by Isaac.