Skip to content

Fix transaction release race - #73

Merged
trowski merged 7 commits into
amphp:2.xfrom
simPod:reproduce-transaction-release-race
Nov 3, 2026
Merged

trowski merged 7 commits into
amphp:2.xfrom
simPod:reproduce-transaction-release-race

Conversation

@simPod

@simPod simPod commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

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
@trowski
trowski force-pushed the reproduce-transaction-release-race branch from f05a54d to c7d2cb5 Compare November 3, 2026 01:37
@trowski
trowski merged commit 49af331 into amphp:2.x Nov 3, 2026
5 checks passed
@simPod
simPod deleted the reproduce-transaction-release-race branch November 3, 2026 02:15
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.

2 participants