You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fire-and-forget (async spawned) CloseStatement on drain/Drop races the session's next request — non-deterministic wire ordering #170
The kernel closes a statement via a detached, fire-and-forget async task on the auto-close-on-drain and Drop paths (runtime.spawn(async move { transport.close_statement(...).await })), rather than awaiting the close at a well-defined point. Because the spawned DELETE /api/2.0/sql/statements/<id> runs on the runtime whenever it's scheduled, it races the connector's next request on the same session, producing non-deterministic wire ordering.
This is distinct from #168 (which is that the close is redundant when the statement is already state=CLOSED). This issue is about the close that does fire being async rather than synchronous.
So the kernel already has a synchronous close; the drain/Drop paths just don't use it.
Evidence of the race
In the databricks-driver-test kernel proxy suite, the identical committed recording replays fail / pass / pass across three back-to-back runs (strict-ordering replay): the spawned CloseStatement DELETE sometimes lands before, sometimes after, the next ExecuteStatement. That non-determinism is only possible if the close is not ordered w.r.t. subsequent requests.
Comparison with the other Databricks SEA drivers (both synchronous)
Both close synchronously at result-set/statement close, so the DELETE never races a later request.
Why it matters
Non-deterministic wire ordering breaks ordered replay/proxy tooling and makes traffic hard to reason about / debug.
Latent beyond metadata: any multi-statement flow on one session (e.g. cloud-fetch/large results followed by another query) can hit the same race.
Suggested fix
Close synchronously on the drain / explicit-close path (await it, as the stmt.close() path already does and as C#/JDBC do). Reserve the fire-and-forget runtime.spawnonly for the true Drop-without-explicit-close GC fallback (where Rust can't .await), not as the primary mechanism for a normally-consumed statement.
Note: fixing #168 (skip the close entirely when the ExecuteStatement response is state=CLOSED) removes the race for the metadata case outright, since no close would be spawned there. This issue covers the remaining cases where a close genuinely must fire.
Found via the databricks-driver-test kernel proxy fan-out. Related: #168.
Recommendation: working as intended — the async close is a deliberate optimization, not a correctness bug
I prototyped the synchronous-close fix (#224, now closed) and, on review, it's the wrong trade. Laying out why, because the distinction matters:
The race has no correctness impact
The auto-close fires DELETE /api/2.0/sql/statements/<id> against a specific, already-terminalstatement_id. The caller's next request is a POST /statements that creates an independent statement with a different id. So the two operations are independent server-side:
The DELETE cannot affect the next statement (different id).
The DELETE cannot affect the session.
The prior statement is already terminal, so nothing is lost regardless of ordering.
Session close (delete_session) does not coordinate with or wait on pending statement closes — and the server reclaims every statement on session delete anyway.
Whether the DELETE lands before or after the next POST is therefore invisible to any client program. Nothing in production behaves differently.
What the async close actually is
It's a deliberate, measured optimization — PR #85 moved Cancel + Close off the critical path of re-execute loops (~10–14% wall-clock win on large-result QRC loops; Execute → CloudFetch → Cancel → Close became Execute → CloudFetch on the hot path, with the close in flight while the consumer is already issuing the next query). C#/JDBC close synchronously, but the kernel intentionally chose async for latency.
Why the synchronous fix is a bad trade
Making the drain close synchronous (as #224 did) re-introduces serially the CloseStatement RTT that #85 moved off the critical path — a real +1 RTT at end-of-stream for every SUCCEEDED / large-CloudFetch statement the caller drains. (Quick state=CLOSED inline queries are unaffected, since #168 already suppresses their close entirely.) That's paying production latency to make an external replay harness's recording deterministic.
The only real symptom, and where it belongs
The non-determinism only affects strict-ordering proxy replay in databricks-driver-test — a test-infrastructure concern. That repo already has the appropriate fix (per-test / per-connection recording, as noted here and in #168). The kernel shouldn't slow down production traffic to accommodate a replay harness's ordering assumption about two independent requests.
If ordering determinism ever becomes worth it
A non-blocking approach is possible: keep the close spawned, but have the next request on the session await any still-pending close before issuing — deterministic ordering with ~0 hot-path latency, preserving #85. Happy to implement that if the replay determinism turns out to cause ongoing pain that the per-connection workaround doesn't cover. Absent that, it's added complexity for a non-problem.
Recommendation: close as working-as-intended. The complementary redundant-close bug (#168) — where a close fires that genuinely shouldn't — is the real defect and is fixed. This issue is about the ordering of a close that is harmless regardless of when it lands.
This issue has been marked as Stale because it has been open for 30 days with no activity. If you would like the issue to remain open, please remove the stale label or comment on the issue.
This issue has been marked as Stale because it has been open for 30 days with no activity. If you would like the issue to remain open, please remove the stale label or comment on the issue.
Activity
vikrantpuppala commentedon Aug 10, 2026
Recommendation: working as intended — the async close is a deliberate optimization, not a correctness bug
I prototyped the synchronous-close fix (#224, now closed) and, on review, it's the wrong trade. Laying out why, because the distinction matters:
The race has no correctness impact
The auto-close fires
DELETE /api/2.0/sql/statements/<id>against a specific, already-terminalstatement_id. The caller's next request is aPOST /statementsthat creates an independent statement with a different id. So the two operations are independent server-side:delete_session) does not coordinate with or wait on pending statement closes — and the server reclaims every statement on session delete anyway.Whether the DELETE lands before or after the next POST is therefore invisible to any client program. Nothing in production behaves differently.
What the async close actually is
It's a deliberate, measured optimization — PR #85 moved
Cancel + Closeoff the critical path of re-execute loops (~10–14% wall-clock win on large-result QRC loops;Execute → CloudFetch → Cancel → ClosebecameExecute → CloudFetchon the hot path, with the close in flight while the consumer is already issuing the next query). C#/JDBC close synchronously, but the kernel intentionally chose async for latency.Why the synchronous fix is a bad trade
Making the drain close synchronous (as #224 did) re-introduces serially the
CloseStatementRTT that #85 moved off the critical path — a real +1 RTT at end-of-stream for every SUCCEEDED / large-CloudFetch statement the caller drains. (Quickstate=CLOSEDinline queries are unaffected, since #168 already suppresses their close entirely.) That's paying production latency to make an external replay harness's recording deterministic.The only real symptom, and where it belongs
The non-determinism only affects strict-ordering proxy replay in databricks-driver-test — a test-infrastructure concern. That repo already has the appropriate fix (per-test / per-connection recording, as noted here and in #168). The kernel shouldn't slow down production traffic to accommodate a replay harness's ordering assumption about two independent requests.
If ordering determinism ever becomes worth it
A non-blocking approach is possible: keep the close spawned, but have the next request on the session
awaitany still-pending close before issuing — deterministic ordering with ~0 hot-path latency, preserving #85. Happy to implement that if the replay determinism turns out to cause ongoing pain that the per-connection workaround doesn't cover. Absent that, it's added complexity for a non-problem.Recommendation: close as working-as-intended. The complementary redundant-close bug (#168) — where a close fires that genuinely shouldn't — is the real defect and is fixed. This issue is about the ordering of a close that is harmless regardless of when it lands.
github-actions commentedon Sep 9, 2026
This issue has been marked as Stale because it has been open for 30 days with no activity. If you would like the issue to remain open, please remove the stale label or comment on the issue.
github-actions commentedon Oct 10, 2026
This issue has been marked as Stale because it has been open for 30 days with no activity. If you would like the issue to remain open, please remove the stale label or comment on the issue.
github-actions commentedon Oct 18, 2026
This issue was closed because it has been inactive for 7 days since being marked as stale.