Repository navigation
Conversation
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Comment |
kensac
force-pushed
the
fix/refuse-statements-on-closing-transaction
branch
from
October 8, 2026 03:59
b80e60a to
4f86d68
Compare
…t starts closing A query keeps the transaction it was given while it runs. When the transaction times out mid-query, adapters that close it by sending ROLLBACK and releasing the connection ran the query's remaining statements outside the transaction, where they committed. getTransaction now returns a view whose queryRaw and executeRaw throw the closed-transaction error once closing has begun. Closes prisma#29762 Signed-off-by: Kanishk Sachdev <kanishksachdev@gmail.com>
kensac
force-pushed
the
fix/refuse-statements-on-closing-transaction
branch
from
October 8, 2026 03:59
4f86d68 to
137600e
Compare
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #29762
Problem
When a transaction times out while a query is still running, the query keeps sending its remaining statements on the transaction it was given. Adapters that close a transaction by sending
ROLLBACKand then releasing the connection (usePhantomQuery: false, such as@prisma/adapter-pg) run those statements after theROLLBACK, outside any transaction, so each one commits on its own. The caller getsP2028and reasonably assumes nothing was written.A nested write is enough to hit it, because it runs as several statements:
Fix
TransactionManager.getTransactionnow returns a view of the transaction whosequeryRawandexecuteRawthrow once the transaction has started closing. The manager sends its ownCOMMITandROLLBACKon the underlying transaction, so closing is unchanged.A refused statement throws the error a new query on that transaction already gets:
TransactionExecutionTimeoutErrorafter a timeout,TransactionClosedErrororTransactionRolledBackErrorotherwise. Callers see no new error. Statements sent before closing began still run inside the transaction and roll back with it.The guard lives in the transaction manager because it is the only place that knows when closing begins. For
usePhantomQuery: falseadapters it sendsROLLBACKthroughexecuteRawand callsrollback()only afterwards, to release the connection. A guard set inrollback()comes too late: a statement queued behind theROLLBACKstill runs. With #29769 applied on its own, the regression test below still fails the same way.Tests
transaction-manager.test.ts: a statement sent while the timeoutROLLBACKis in flight is refused and never reaches the driver. Statements on a committed or rolled-back transaction are refused. Both tests fail without the fix.issues/29762-timed-out-transaction-nested-write(PostgreSQL, run withjs_pg): another transaction holds aFOR NO KEY UPDATElock, so the nested write'sUPDATEoutlives a 1s timeout. The test asserts the batch rejects withP2028and nothing was written. Without the fix, both posts commit.