Skip to content

chore(spanner): wait until queries have started before closing ReadContext#12727

Open
olavloite wants to merge 2 commits intomainfrom
spanner-wait-for-queries-to-start-before-close
Open

chore(spanner): wait until queries have started before closing ReadContext#12727
olavloite wants to merge 2 commits intomainfrom
spanner-wait-for-queries-to-start-before-close

Conversation

@olavloite
Copy link
Copy Markdown
Contributor

Prevents a ReadContext from being closed before all queries have actually started. This extra check is needed now that queries in read-only transactions are started using the background executor when the async API is used.

Follow-up for #12715

@olavloite olavloite requested review from a team as code owners April 9, 2026 13:31
…ntext

Prevents a ReadContext from being closed before all queries have actually started. This
extra check is needed now that queries in read-only transactions are started using the
background executor when the async API is used.
@olavloite olavloite force-pushed the spanner-wait-for-queries-to-start-before-close branch from fe4c184 to 6a2c9db Compare April 9, 2026 13:48
Copy link
Copy Markdown
Contributor

@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 updates the locking mechanism in AbstractReadContext.java by replacing the intrinsic object lock with a ReentrantLock and a Condition variable to manage pending asynchronous operations. It also introduces an AtomicInteger to track pending starts and ensures that the close() method waits for all pending operations to complete. I have reviewed the implementation and agree with the feedback provided regarding a potential resource leak: if the AsyncResultSetImpl constructor throws an exception, the pendingStarts counter will not be decremented, causing the close() method to hang. The suggested fix to wrap the constructor in a try-catch block is necessary to ensure the counter is correctly decremented in failure scenarios.

@olavloite olavloite force-pushed the spanner-wait-for-queries-to-start-before-close branch from abdf020 to 92e7777 Compare April 9, 2026 14:45
@olavloite olavloite force-pushed the spanner-wait-for-queries-to-start-before-close branch from 92e7777 to fb98e5d Compare April 9, 2026 16:07
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