Skip to content

fix(spanner): prevent deadlock if ResultSet#next() is never called (step 5)#5654

Merged
olavloite merged 6 commits into
googleapis:mainfrom
olavloite:spanner-inline-begin-tx-step-5-new
May 13, 2026
Merged

fix(spanner): prevent deadlock if ResultSet#next() is never called (step 5)#5654
olavloite merged 6 commits into
googleapis:mainfrom
olavloite:spanner-inline-begin-tx-step-5-new

Conversation

@olavloite
Copy link
Copy Markdown
Contributor

If a query included a BeginTransaction option and the application never called ResultSet#next(), then the transaction ID would never be returned. This would block any other query from using the transaction. This change refactors ResultSet to use a background worker to read from the stream. This prevents that a deadlock can happen if the application does not call ResultSet#next(). It also allows the application to call ResultSet#metadata() without first calling ResultSet#next(). Finally, it also allows the ResultSet to decode data from the server asynchronously while the application processes rows that it has already read from the ResultSet.

Replaces #5324 due to too massive merge conflicts.

olavloite added 2 commits May 12, 2026 11:23
…tep 5)

If a query included a BeginTransaction option and the application never called ResultSet#next(),
then the transaction ID would never be returned. This would block any other query from using
the transaction. This change refactors ResultSet to use a background worker to read from the
stream. This prevents that a deadlock can happen if the application does not call ResultSet#next().
It also allows the application to call ResultSet#metadata() without first calling ResultSet#next().
Finally, it also allows the ResultSet to decode data from the server asynchronously while the
application processes rows that it has already read from the ResultSet.

Replaces googleapis#5324 due to too massive merge conflicts.
@olavloite olavloite requested review from a team as code owners May 12, 2026 09:32
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the Spanner API. label May 12, 2026
@olavloite olavloite requested a review from sakthivelmanii May 12, 2026 09:32
@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

❌ Patch coverage is 95.09804% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.92%. Comparing base (fb4a284) to head (e6e5c89).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/spanner/src/result_set.rs 95.04% 15 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5654      +/-   ##
==========================================
- Coverage   97.92%   97.92%   -0.01%     
==========================================
  Files         221      222       +1     
  Lines       52759    53183     +424     
==========================================
+ Hits        51663    52077     +414     
- Misses       1096     1106      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

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

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 ResultSet to utilize a background worker task for stream processing, making ResultSet::metadata asynchronous and fixing a potential deadlock in lazy transaction starts. Review feedback identifies that ResultSet is no longer Sync due to the new mpsc::Receiver field, which may break existing code, and notes a style guide violation concerning the use of unwrap() in production logic.

Comment thread src/spanner/src/result_set.rs
Comment thread src/spanner/src/result_set.rs Outdated
@olavloite olavloite merged commit fc959c0 into googleapis:main May 13, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the Spanner API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants