Skip to content

fix(spannerlib): gracefully handle missing stats for single statements - #887

Open
surbhigarg92 wants to merge 1 commit into
mainfrom
read_stats_issue
Open

fix(spannerlib): gracefully handle missing stats for single statements#887
surbhigarg92 wants to merge 1 commit into
mainfrom
read_stats_issue

Conversation

@surbhigarg92

Copy link
Copy Markdown
Contributor

In readStats, normal (non-profiled) single-statement queries do not
return a trailing stats result set. The previous implementation returned
a "stats results not found" error, which disrupted normal execution.
This fix returns nil instead, allowing the EOF auto-close logic to
complete successfully without phantom errors.

@surbhigarg92
surbhigarg92 requested a review from a team as a code owner July 27, 2026 11:53

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the nextBatch method in spannerlib/api/rows.go to unconditionally read statistics, and modifies readStats to return nil instead of an internal error when there are no more result sets. The feedback suggests returning rows.backend.Err() instead of nil unconditionally when NextResultSet() returns false, in order to avoid swallowing underlying errors.

Comment thread spannerlib/api/rows.go
Comment on lines 398 to 400
if !rows.backend.NextResultSet() {
return status.Error(codes.Internal, "stats results not found")
return nil
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When rows.backend.NextResultSet() returns false, it can be either because there are no more result sets or because an error occurred during the operation. Returning nil unconditionally will swallow any such errors. Instead, return rows.backend.Err() to correctly propagate any underlying errors while still returning nil when there are no more result sets.

Suggested change
if !rows.backend.NextResultSet() {
return status.Error(codes.Internal, "stats results not found")
return nil
}
if !rows.backend.NextResultSet() {
return rows.backend.Err()
}

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