Skip to content

Avoid waiting for cleanup of drained async statements - #507

Closed
vuanhphung wants to merge 17 commits into
mainfrom
perf/async-close
Closed

vuanhphung wants to merge 17 commits into
mainfrom
perf/async-close

Conversation

@vuanhphung

@vuanhphung vuanhphung commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Description

After an async result is fully read, close() no longer waits for the CloseStatement round trip: it releases the handle and sends the DELETE in the background. Closing an undrained result still waits. Independent of #459 and #472.

To keep close-then-state callers correct (for example the Python connector's close_command → get_query_state), same-session attach/status and the owner's await_result()/fetch_result() wait for that DELETE before reading server state, so they still see CLOSED. Drop stays fire-and-forget, as on main.

Behavior changes:

  • Cleanup errors after a drained close are logged (WARN, or DEBUG once the session is closing), not returned, and Drop doesn't retry them.
  • Other sessions may see SUCCEEDED until the DELETE lands.
  • After Session::close, statements skip CloseStatement. If DeleteSession failed, a still-running dropped statement isn't cancelled; the server reclaims it with the session at idle timeout.
  • Background DELETEs aren't capped. Only explicit async callers gain; close-then-status callers break even.

Testing

Async SELECT 1, live warehouse, median (p90) main this PR
close() 116.4 (145.6) ms 0.005 (0.008) ms
End to end 322.4 (370.6) ms 201.7 (222.0) ms

n=30 per variant in fresh processes with rotated order; no WARN/ERROR lines. Measured at 2388a85; later commits don't touch the drained-close path, and a rerun at 679d21a matched.

Unit, wiremock (DELETE held until the test releases it; 0 failures under concurrent load), napi, pyo3 and live async e2e tests pass. The Python connector's close → state reads CLOSED 10/10. Removing any of the new waits, the closed-session skip or the log-level choice fails a test.

Adversarial review: 3 rounds, converged; review bot approved 35e709b.

This pull request and its description were written by Isaac.

Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a 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.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 2 Nit

Looks good: 2 low concerns. The drained-close detach logic, the drain signal's error handling and the Drop refactor all look correct, and the tests cover the mock-server and live-warehouse paths.

Other findings

  • ⚪ Nit — napi/index.d.ts is the generated binding file and still carries the old close() doc, because the Rust doc comment changed in this PR without regenerating it. Regenerate index.d.ts, or edit it by hand, and commit it. (Found by Claude Opus 5.5 · confirmed by the judge)
  • ⚪ Nit — The new tests/v0_async_close_logging_wiremock.rs starts directly with use and has no Apache 2.0 license header. Every sibling test file begins with // Copyright (c) 2026 Databricks, Inc. and the license block. Add the standard header. (Found by Claude Opus 5.5 · confirmed by the judge)

Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a 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.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 Low · 1 Nit

Looks good, with 2 low concerns. Background cleanup after a drained close is gated correctly on the closed swap and the DeleteSession result, and the same-session wait lets status fall through to GET on timeout or failure. Test coverage is thorough at the unit, wiremock and e2e levels.

Other findings

  • ⚪ Nit — Tests named reviewer_* print REVIEWER ... diagnostics with eprintln! on every run, which looks like leftover review-harness debugging. Rename the tests after the behavior they pin and remove the eprintln! calls. (Found by Claude Opus 5.5 · confirmed by the judge)

Comment thread src/session.rs Resolved
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
@vuanhphung

Copy link
Copy Markdown
Collaborator Author

Fixed the test-harness nit in bd95fd5: renamed the three reviewer-prefixed tests by behavior and removed the REVIEWER eprintln! diagnostics; assertions remain.


This comment was generated with GitHub MCP.

@oss-reviewer-bot oss-reviewer-bot Bot left a 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.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 2 Low

Mostly solid: 1 medium and 1 low concern. The drained-close detach and the per-session completion registry look correct and are well tested. The concerns are how long same-session status can wait on a retrying DELETE, and close-failure warnings staying at DEBUG after a failed session close.

Comment thread src/session.rs Resolved
Comment thread src/session.rs Resolved
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a 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.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 Low

Mostly solid, with 1 medium concern. Drained close now detaches cleanup correctly, with good wiremock and e2e coverage. The new same-session wait-for-cleanup is bounded only by the HTTP overall timeout, so it can stall status polling for a long time.

Comment thread src/statement/executed_async.rs Resolved
vuanhphung and others added 3 commits December 2, 2026 04:55
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a 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.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 Low

Looks good, with 2 low concerns. Drained close detaches its cleanup correctly. In-flight closes are deduplicated per session, same-session status/attach wait for cleanup with a time bound, and the wiremock, unit and e2e tests cover the new paths.

This overview is Claude Opus 5.5's initial take; some of its points were set aside by the cross-check judge — see the findings below.

🔀 1 finding considered and dismissed by the judge
  • 🔵 Low src/session.rs:887 — Session::close sets close_initiated to true before delete_session runs, and nothing resets it if the call fails. closed stays false, so the session is s
    Judge's evidence: pub async fn close(self) -> Result<()> {

Comment thread tests/close_regressions/mod.rs Resolved
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a 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.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 Low

Looks solid overall, with 1 medium concern. The same-session wait only covers attach and status, so result polling on attached handles can still race the background DELETE.

Comment thread src/statement/executed_async.rs Resolved
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a 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.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 Low

Looks good, with 1 low concern. The drained-close detach, the per-session dedup of in-flight closes and the bounded same-session waits look sound, and wiremock, unit and e2e tests cover them.

Comment thread src/session.rs Resolved
vuanhphung and others added 2 commits December 2, 2026 07:32
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a 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.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

✅ No issues identified.

🔀 1 finding considered and dismissed by the judge
  • 🔵 Low src/session.rs:118 — wait drops the tokio::time::timeout result with let _, so if the cleanup budget runs out, attach/status quietly reads server state that can still show SUC
    Judge's evidence: let _ = tokio::time::timeout(budget, completion.changed()).await;

@vuanhphung

Copy link
Copy Markdown
Collaborator Author

Closing: this only speeds up an explicit close() on a drained async result, which none of the connector benchmarks time, and it changes cleanup semantics. Not worth the added complexity.

This branch was successfully deployed

1 active deployment
azure-prod — 35e709bf Deployed Dec 2, 2026 by vuanhphung via review #1709
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