Skip to content

fix(client-engine-runtime): abort transaction on maxWait timeout - #28723

Merged
aqrln merged 6 commits into
mainfrom
aqrln-zlzqrrouklym
Nov 27, 2025
Merged

aqrln merged 6 commits into
mainfrom
aqrln-zlzqrrouklym

Conversation

@aqrln

@aqrln aqrln commented Nov 25, 2025 •

Copy link
Copy Markdown
Member

When exceeding the maxWait time when trying to start a new transaction, we would incorrectly wait until the transaction is started after all (potentially hanging infinitely), and only then reject startTransaction after the fact if the overall time spent was larger than expected. This is not the intended behavior, startTransaction must reject as soon as the maxWait time is exceeded.

Additionally, we were potentially leaking the transaction timer and transaction object if starting the transaction timed out, and incorrectly issuing rollbacks on transactions that failed to start (and therefore cannot execute any commands including rollback).

This PR only implements what's necessary to fix the test, but there's a few more issues around that area I discovered during investigation that I'd like to fix in follow up PRs:

  • Ideally startTransaction in driver adapter interface would accept an optional AbortSignal and abort starting the transaction on the driver level if it supports it.
  • We should store the set of AbortSignals for the transactions currently starting, and abort them in cancelAllTransactions.
  • The reported time taken in TransactionExecutionTimeoutError is incorrect, it must only include the time since the actual start of the transaction.
  • Type safety issue in switch (transaction.status) in #startTransactionImpl, TypeScript incorrectly narrows the type of transaction and the switch is missing the closing state (which should throw TransactionInternalConsistencyError if detected), see https://prisma-company.slack.com/archives/C058VM009HT/p1764084522869619
  • Code flow can be substantially simplified, automatically resolving the previous two issues, if we don't use the same type for transactions that haven't yet started and don't store them in this.transactions, remove the waiting state and make TransactionWrapper#transaction a non-optional field.

Closes: https://linear.app/prisma-company/issue/ORM-1408/failing-issues9678-test-with-qcaccelerate

@github-actions

github-actions Bot commented Nov 25, 2025 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
packages/client/runtime/index-browser.js 2.23 KB (0%)
packages/client/runtime/index-browser.d.ts 3.28 KB (0%)
packages/cli/build/index.js 2.51 MB (0%)
packages/client/prisma-client-0.0.0.tgz 10.22 MB (+0.02% 🔺)
packages/cli/prisma-0.0.0.tgz 6.71 MB (0%)
packages/bundle-size/da-workers-libsql/output.tgz 804.83 KB (+0.02% 🔺)
packages/bundle-size/da-workers-neon/output.tgz 858.57 KB (+0.02% 🔺)
packages/bundle-size/da-workers-pg/output.tgz 851.44 KB (+0.02% 🔺)
packages/bundle-size/da-workers-planetscale/output.tgz 804.2 KB (+0.02% 🔺)
packages/bundle-size/da-workers-d1/output.tgz 787.73 KB (+0.02% 🔺)

@aqrln
aqrln force-pushed the aqrln-zlzqrrouklym branch from 43311b9 to 46a0c27 Compare November 26, 2025 13:06
@aqrln aqrln added this to the 7.1.0 milestone Nov 26, 2025
When exceeding the `maxWait` time when trying to start a new
transaction, we would incorrectly wait until the transaction is started
aftera all (potentially hanging infinitely), and only then reject
`startTransaction` after the fact if the overall time spent was larger
than expected. This is not the intended behavior, `startTransaction`
must reject as soon as the `maxWait` time is exceeded.
@aqrln
aqrln force-pushed the aqrln-zlzqrrouklym branch from 46a0c27 to c8c64bd Compare November 26, 2025 13:09
@aqrln
aqrln marked this pull request as ready for review November 26, 2025 13:52
@aqrln
aqrln merged commit 0847487 into main Nov 27, 2025
@aqrln
aqrln deleted the aqrln-zlzqrrouklym branch November 27, 2025 10:32
aqrln added a commit that referenced this pull request Dec 3, 2025
#28723 fixed some issues in
transaction startup but introduced a new bug: if the transaction manages
to start in background after we timed out, we would leak a connection in
the connection pool. This PR fixes that by waiting until the transaction
starts in background and immediately rolling it back if it does,
ignoring errors.
aqrln added a commit that referenced this pull request Dec 3, 2025
#28723 fixed some issues in
transaction startup but introduced a new bug: if the transaction manages
to start in background after we timed out, we would leak a connection in
the connection pool. This PR fixes that by waiting until the transaction
starts in background and immediately rolling it back if it does,
ignoring errors.
aqrln added a commit that referenced this pull request Dec 3, 2025
#28723 fixed some issues in
transaction startup but introduced a new bug: if the transaction manages
to start in background after we timed out, we would leak a connection in
the connection pool. This PR fixes that by waiting until the transaction
starts in background and immediately rolling it back if it does,
ignoring errors.
aqrln added a commit that referenced this pull request Dec 3, 2025
#28723 fixed some issues in
transaction startup but introduced a new bug: if the transaction manages
to start in background after we timed out, we would leak a connection in
the connection pool. This PR fixes that by waiting until the transaction
starts in background and immediately rolling it back if it does,
ignoring errors.
aqrln added a commit that referenced this pull request Dec 3, 2025
#28723 fixed some issues in
transaction startup but introduced a new bug: if the transaction manages
to start in background after we timed out, we would leak a connection in
the connection pool. This PR fixes that by waiting until the transaction
starts in background and immediately rolling it back if it does,
ignoring errors.
aqrln added a commit that referenced this pull request Dec 3, 2025
#28723 fixed some issues in
transaction startup but introduced a new bug: if the transaction manages
to start in background after we timed out, we would leak a connection in
the connection pool. This PR fixes that by waiting until the transaction
starts in background and immediately rolling it back if it does,
ignoring errors.
aqrln added a commit that referenced this pull request Dec 4, 2025
#28723 fixed some issues in
transaction startup but introduced a new bug: if the transaction manages
to start in background after we timed out, we would leak a connection in
the connection pool. This PR fixes that by waiting until the transaction
starts in background and immediately rolling it back if it does,
ignoring errors.

Likely fixes
https://linear.app/prisma-company/issue/TML-1648/investigate-itx-tests-failing-with-timeout

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Improved transaction startup timeout handling: if a transaction times
out but later completes, the system now ensures the transaction is
rolled back and connections are released to prevent resource leaks and
performance issues.

* **Tests**
* Added tests covering timeouts during transaction startup and verifying
cleanup occurs once the transaction eventually starts.

<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
aqrln added a commit that referenced this pull request Dec 5, 2025
#28723 fixed some issues in
transaction startup but introduced a new bug: if the transaction manages
to start in background after we timed out, we would leak a connection in
the connection pool. This PR fixes that by waiting until the transaction
starts in background and immediately rolling it back if it does,
ignoring errors.

Likely fixes
https://linear.app/prisma-company/issue/TML-1648/investigate-itx-tests-failing-with-timeout

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Improved transaction startup timeout handling: if a transaction times
out but later completes, the system now ensures the transaction is
rolled back and connections are released to prevent resource leaks and
performance issues.

* **Tests**
* Added tests covering timeouts during transaction startup and verifying
cleanup occurs once the transaction eventually starts.

<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
aqrln added a commit that referenced this pull request Dec 5, 2025
#28723 fixed some issues in
transaction startup but introduced a new bug: if the transaction manages
to start in background after we timed out, we would leak a connection in
the connection pool. This PR fixes that by waiting until the transaction
starts in background and immediately rolling it back if it does,
ignoring errors.

Likely fixes
https://linear.app/prisma-company/issue/TML-1648/investigate-itx-tests-failing-with-timeout

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Improved transaction startup timeout handling: if a transaction times
out but later completes, the system now ensures the transaction is
rolled back and connections are released to prevent resource leaks and
performance issues.

* **Tests**
* Added tests covering timeouts during transaction startup and verifying
cleanup occurs once the transaction eventually starts.

<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
nams1570 added a commit to hexclave/hexclave that referenced this pull request Oct 13, 2026
)

7.1.0 has a race where the connection slot can be lost if a p2028 is
encountered. This version is the first to truly fix it.
[Here's a PR from prisma](prisma/orm#28723)
which acknowledges the issue, which was shipped as part of 7.1.0.


<!--

Make sure you've read the CONTRIBUTING.md guidelines:
https://github.com/hexclave/hexclave/blob/dev/CONTRIBUTING.md

-->


<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Upgrades Prisma from 7.1.0 to 7.10.0 to fix a race condition where a
P2028 error could permanently drop a connection pool slot; 7.10.0 is the
first release with a proper fix.

**Dependencies**
- Bumps `@prisma/adapter-pg`, `@prisma/client`,
`@prisma/instrumentation`, and `prisma` to 7.10.0.
- Refreshes `pnpm-lock.yaml` with the updated transitive deps pulled in
by the Prisma upgrade.

<sup>Written for commit c41439f.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/hexclave/hexclave/pull/2110?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="View guided diff"
src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>
<a
href="https://www.cubic.dev/action/auto-fix/pr/hexclave/hexclave/2110?returnTo=https%3A%2F%2Fgithub.com%2Fhexclave%2Fhexclave%2Fpull%2F2110&source=description"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img
alt="Turn on auto-fix"
src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Chores**
* Updated backend platform components to newer versions. No changes to
user-facing features or behavior are included in this release.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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