Skip to content

fix(adapter-planetscale): propagate COMMIT errors in transactions#29155

Merged
jacek-prisma merged 2 commits intoprisma:mainfrom
chaba11:fix/adapter-planetscale-propagate-commit-error
Feb 9, 2026
Merged

fix(adapter-planetscale): propagate COMMIT errors in transactions#29155
jacek-prisma merged 2 commits intoprisma:mainfrom
chaba11:fix/adapter-planetscale-propagate-commit-error

Conversation

@chaba11
Copy link
Copy Markdown
Contributor

@chaba11 chaba11 commented Feb 9, 2026

Problem

Fixes #29138

When PlanetScale's vttablet kills a transaction server-side (e.g., 20-second timeout), @prisma/adapter-planetscale silently swallows the COMMIT failure. Prisma resolves the operation as successful and returns data from the uncommitted transaction, but nothing is actually persisted. This causes silent data loss in production.

Root Cause

In startTransactionInner(), the outer Promise is resolve()d inside the conn.transaction() callback — before the transaction completes. When COMMIT later fails:

  1. The error hits .catch()
  2. .catch() calls reject(error) — but the Promise is already resolved, so this is a no-op
  3. .catch() returns undefined, so txResultPromise resolves successfully
  4. commit() awaits txResultPromise → resolves → silent data loss

Fix

One-line change: replace return reject(error) with throw error.

When we throw instead of calling the already-settled reject():

  • txResultPromise (the .catch() chain result) rejects with the error
  • commit() awaits txResultPromise → throws → error propagates to the consumer

Tests

Added 3 test cases:

  • commit succeeds when conn.transaction() resolves — no regression on happy path
  • commit throws when conn.transaction() rejects after COMMIT failure — verifies the fix
  • rollback does not throw (RollbackError is swallowed) — no regression on rollback

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling in transaction operations to ensure errors propagate correctly during commit failures.
  • Tests

    • Added comprehensive test coverage for transaction commit, rollback, and error scenarios in the PlanetScale adapter.

…ng them

Fixes prisma#29138

When PlanetScale's vttablet kills a transaction server-side, the COMMIT
failure was silently swallowed because `reject(error)` was called on an
already-resolved Promise (resolved earlier via `resolve(txWrapper)`).

Replace `return reject(error)` with `throw error` so that `txResultPromise`
rejects, which propagates the error through `commit()` to the consumer.
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Feb 9, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 9, 2026

Walkthrough

Fixes a critical bug in the PlanetScale adapter where transaction COMMIT errors were silently swallowed. Replaces the error rejection path with exception throwing in startTransactionInner and adds test coverage for transaction commit, rollback, and error propagation scenarios.

Changes

Cohort / File(s) Summary
Transaction Error Handling
packages/adapter-planetscale/src/planetscale.ts
Changes error handling in startTransactionInner from attempting to reject an already-resolved promise to throwing the error instead. Non-RollbackError exceptions now propagate correctly while RollbackError behavior is preserved.
Test Coverage
packages/adapter-planetscale/src/planetscale.test.ts
Introduces new test suite for startTransaction / commit / rollback with helper functions (createAdapterWithMockConnection, deferredTransaction) and tests for successful commit, commit error propagation, and rollback behavior.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(adapter-planetscale): propagate COMMIT errors in transactions' directly summarizes the main change: fixing error propagation in transaction commits.
Linked Issues check ✅ Passed The PR fulfills all requirements from issue #29138: replaces reject() with throw to propagate COMMIT errors, adds three comprehensive tests, and fixes the Promise-handling bug causing silent data loss.
Out of Scope Changes check ✅ Passed All changes in planetscale.ts and planetscale.test.ts directly address the COMMIT error propagation issue with no unrelated modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Feb 9, 2026

Merging this PR will degrade performance by 29.41%

⚡ 1 improved benchmark
❌ 1 regressed benchmark
✅ 39 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
compile update simple 2.6 ms 1.6 ms +64.58%
compile upsert 1.3 ms 1.9 ms -29.41%

Comparing chaba11:fix/adapter-planetscale-propagate-commit-error (f8305c2) with main (1e6c91c)

Open in CodSpeed

@jacek-prisma jacek-prisma merged commit 8410fea into prisma:main Feb 9, 2026
254 of 256 checks passed
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.

bug: @prisma/adapter-planetscale silently swallows transaction COMMIT errors, causing data loss

3 participants