FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(spanner): release transaction lock if inline begin fails by olavloite · Pull Request #18409 · googleapis/google-cloud-python · GitHub

Repository navigation

fix(spanner): release transaction lock if inline begin fails - #18409

Merged
olavloite merged 1 commit into
mainfrom
spanner-release-tx-lock-on-fail
Sep 17, 2026
Merged

olavloite merged 1 commit into
mainfrom
spanner-release-tx-lock-on-fail

Conversation

Copy link
Copy Markdown
Contributor

When execute_update() or batch_update() starts an inline begin (transaction_id is None), it acquires self._lock while waiting for the transaction ID from the server. If that request failed with an error, the lock was never released.

This was a latent bug in _async/transaction.py that became an active deadlock when async/sync parity was recently restored in snapshot.py: reintroducing _wait_for_transaction_begin() meant subsequent queries in the same transaction now try to acquire self._lock and hang.

Wrap the request execution in try...finally in _async/transaction.py and regenerate sync transaction.py so self._lock is always released.

Also:

  • Add unit tests for failed inline begin in both async and sync clients.
  • Add a GitHub Actions workflow to run Spanner mock server tests in CI.
  • Include the mockserver session in default local Nox runs.

olavloite requested review from a team as code owners September 17, 2026 11:41

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Code Review

This pull request introduces try-finally blocks in both the synchronous and asynchronous implementations of execute_update and batch_update within the Google Cloud Spanner transaction modules. This ensures that the transaction lock is safely released if an error occurs during an inline begin. Unit tests have been added to verify that the lock is released upon failure, and mockserver has been added to the noxfile. There are no review comments, so I have no feedback to provide.

When execute_update() or batch_update() starts an inline begin
(transaction_id is None), it acquires self._lock while waiting for
the transaction ID from the server. If that request failed with an
error, the lock was never released.

This was a latent bug in _async/transaction.py that became an active
deadlock when async/sync parity was recently restored in snapshot.py:
reintroducing _wait_for_transaction_begin() meant subsequent queries
in the same transaction now try to acquire self._lock and hang.

Wrap the request execution in try...finally in _async/transaction.py
and regenerate sync transaction.py so self._lock is always released.

Also:
- Add unit tests for failed inline begin in both async and sync clients.
- Add a GitHub Actions workflow to run Spanner mock server tests in CI.
- Include the mockserver session in default local Nox runs.
olavloite force-pushed the spanner-release-tx-lock-on-fail branch from 5769984 to 16d474c Compare September 17, 2026 12:02
olavloite enabled auto-merge (squash) September 17, 2026 12:33
olavloite merged commit dd24029 into main Sep 17, 2026
130 of 179 checks passed
olavloite deleted the spanner-release-tx-lock-on-fail branch September 17, 2026 12:36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

2 participants


Back | FazBrowse Home | New Git URL