Repository navigation
fix(telemetry): finalize statement telemetry on sync close #299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -151,6 +151,46 @@ impl ExecutedStatement { | |
| Ok(None) | ||
| } | ||
|
|
||
| /// Explicit close for concrete sync statements. | ||
| /// | ||
| /// This finalizes result-stream telemetry before the server-side | ||
| /// `CloseStatement` RPC so partial-result closes emit the same terminal | ||
| /// statement event as full result exhaustion. | ||
| pub async fn close(&mut self) -> Result<()> { | ||
| self.result_stream.finish_telemetry(); | ||
| self.close_server_statement().await | ||
| } | ||
|
|
||
| async fn close_server_statement(&self) -> Result<()> { | ||
| // Idempotent on success: a prior successful close sets | ||
| // `closed=true` and subsequent calls short-circuit. | ||
| // | ||
| // On wire failure we deliberately keep `closed=false` so that | ||
| // `Drop`'s fire-and-forget retry path runs as a fallback — | ||
| // otherwise a transient close failure would silently leak the | ||
| // server-side statement until session expiry. Mirrors | ||
| // `Session::close`. | ||
| // | ||
| // The `&self` signature allows two callers to race and both | ||
| // hit the wire. The server-side close is idempotent (it | ||
| // returns the same Ok for duplicate close_statement calls), | ||
| // so the only cost of the race is one redundant RPC — far | ||
| // better than dropping the retry contract. | ||
| async { | ||
| if self.closed.load(Ordering::Acquire) { | ||
| return Ok(()); | ||
| } | ||
| self.session | ||
| .transport() | ||
| .close_statement(&self.statement_id) | ||
| .await?; | ||
| self.closed.store(true, Ordering::Release); | ||
| Ok(()) | ||
| } | ||
| .instrument(self.session.log_span().clone()) | ||
| .await | ||
| } | ||
|
|
||
| /// Spawn a fire-and-forget `CloseStatement` unless the statement is | ||
| /// already closed (`closed` flag). Shared by [`Self::next_batch`]'s | ||
| /// auto-close-on-drain and `Drop`. The `swap` makes whichever fires | ||
|
|
@@ -297,33 +337,7 @@ impl ExecutedStatementHandle for ExecutedStatement { | |
| } | ||
|
|
||
| async fn close(&self) -> Result<()> { | ||
| // Idempotent on success: a prior successful close sets | ||
| // `closed=true` and subsequent calls short-circuit. | ||
| // | ||
| // On wire failure we deliberately keep `closed=false` so that | ||
| // `Drop`'s fire-and-forget retry path runs as a fallback — | ||
| // otherwise a transient close failure would silently leak the | ||
| // server-side statement until session expiry. Mirrors | ||
| // `Session::close`. | ||
| // | ||
| // The `&self` signature allows two callers to race and both | ||
| // hit the wire. The server-side close is idempotent (it | ||
| // returns the same Ok for duplicate close_statement calls), | ||
| // so the only cost of the race is one redundant RPC — far | ||
| // better than dropping the retry contract. | ||
| async { | ||
| if self.closed.load(Ordering::Acquire) { | ||
| return Ok(()); | ||
| } | ||
| self.session | ||
| .transport() | ||
| .close_statement(&self.statement_id) | ||
| .await?; | ||
| self.closed.store(true, Ordering::Release); | ||
| Ok(()) | ||
| } | ||
| .instrument(self.session.log_span().clone()) | ||
| .await | ||
| self.close_server_statement().await | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 Low — The new inherent The two in-tree explicit-close call sites (PyO3, NAPI) now route through the concrete Not a regression (the trait method's behavior is unchanged) and drop-time finalization remains a backstop, so severity is low. Worth a doc note on the trait (Anchored to the nearest changed line — see the description for the exact location.) |
||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔵 Low —
ExecutedStatementnow has two identically-namedclosemethods with divergent behavior: the inherentclose(&mut self)(this line) finalizes result-stream telemetry beforeCloseStatement, while the trait implExecutedStatementHandle::close(&self)(executed.rs:339) only callsclose_server_statement()and relies on drop-time finalization. Method resolution silently picks one based on the receiver's mutability/import context — which is exactly why the pyo3/napi call sites had to be rewritten to fully-qualifiedType::close(&mut ...)form to hit the finalizing path.This is a maintenance footgun: a future caller that acquires the handle behind the trait object (or an
&selfbinding) will get the non-finalizing path and lose the "terminal statement event emitted before close" guarantee this PR establishes — the event would still fire at Drop, but the ordering/timing contract in the inherent method's doc comment would be quietly broken. Consider a doc note on the trait impl pointing at the inherent method, or (better) unifying so both paths finalize telemetry. Not a correctness bug today since Drop backstops finalization and the two shipped call sites are correct.