Repository navigation
fix(client): stop a late nested commit from committing the outer transaction - #31332
benjibunbun wants to merge 1 commit into
Conversation
…saction If an interactive transaction's callback finished while a nested transaction was still running a query, the outer scope rolled back every level but only reset the scope stack after those rollbacks. The first rollback waits for the running query, so the nested callback could finish in between, still see itself as the active scope and send a commit, which committed the top-level transaction. Reset the stack before rolling back. Signed-off-by: ben <226082140+benjibunbun@users.noreply.github.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Linked issue
Refs #31301
This fixes the two cases where the outer callback throws or returns while a nested
tx.$transactionis still running. The third case in the issue isn't covered, see the notes below.Summary
If the outer callback finishes while a nested transaction is still running a query, the outer scope rolls back every level, but it only reset the scope stack after those rollbacks. The first rollback waits for the running query, so the nested callback could finish in between, still see itself as the active scope and send
commit, which committed the top-level transaction. The stack is now reset before the rollbacks, so the nested callback rejects instead.Testing performed
interactive-transactions: the outer callback throws or returns while the nested transaction is runningpg_sleep. Onv7both leave the outer write committed, and they pass with this change.pnpm --filter @prisma/client test:functional:code interactive-transactionswith--adapter js_pg,--adapter js_better_sqlite3and--provider postgresql --remote-executor, plustest:functional --types-onlyfor the suite.js_pgandjs_better_sqlite3.Skill update
n/a — internal only
Checklist
git commit -s) per the DCO. The DCO status check will block merge if any commit is missing aSigned-off-by:trailer.n/aif the change is doc-only / refactor with no behavioural delta).n/aif this is not a bug fix).n/a — internal only).Notes for the reviewer
Nested transactions must be closed in reverse order of creation., the error a scope already gets once it's no longer on the stack. Before, it sentcommitand resolved.txwhile a nested transaction is open, then the nested one fails) isn't fixed. That write runs in the nested level because both share one transaction id, which fix(client): a statement can no longer run after its transaction has closed #30995 kept on purpose. Changing it needs separate ids per level in the transaction manager, so I think it's better as its own change.Assisted by Claude Code.
Summary by CodeRabbit