Skip to content

Fix transaction release race#73

Open
simPod wants to merge 2 commits into
amphp:2.xfrom
simPod:reproduce-transaction-release-race
Open

Fix transaction release race#73
simPod wants to merge 2 commits into
amphp:2.xfrom
simPod:reproduce-transaction-release-race

Conversation

@simPod

@simPod simPod commented Jun 23, 2026

Copy link
Copy Markdown

This fixes a transaction release race in PostgresHandleConnection.

The first commit adds a regression test that opens a transaction, commits it, and immediately opens another transaction. Before the fix, the previous transaction's close callback releases the connection lock asynchronously, so the second beginTransaction() can observe the connection as still busy.

Observed before the fix with assertions enabled:

assert($this->busy === null) in src/Internal/PostgresHandleConnection.php:85

Observed before the fix with assertions disabled, matching the production symptom:

Amp\Future\UnhandledFutureError: Unhandled future: Error: "Call to a member function complete() on null"
Caused by Error: Call to a member function complete() on null
src/Internal/PostgresHandleConnection.php:96
vendor/amphp/sql-common/src/SqlConnectionTransaction.php:100

The second commit makes beginTransaction() wait for any pending transaction release before reserving the connection again, matching the behavior already used by query, execute, prepare, notify, and listen.

@simPod simPod changed the title Add failing test for transaction release race Fix transaction release race Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant