fix(adapter-mssql): acquire mutex in commit/rollback to prevent EREQINPROG error#29119
fix(adapter-mssql): acquire mutex in commit/rollback to prevent EREQINPROG error#29119MarkusLund wants to merge 1 commit intoprisma:mainfrom
Conversation
WalkthroughAdds mutex-based serialization to MSSQL transaction commit and rollback, and a test suite that reproduces the pre-fix race and verifies serialization, ordering, and error handling (EABORT, non-EABORT, concurrent queries) with and without the mutex. Changes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@packages/adapter-mssql/src/mssql.test.ts`:
- Around line 173-182: Add a unit test that mirrors the rollback
error-propagation test but for commit: mockTransaction.commit should be mocked
to return a rejected Promise with an Error having message "Connection lost" and
code 'ECONNCLOSED', then call createTransaction(true) and assert that
tx.commit() rejects with that error message; reference mockTransaction.commit
and the commit method on the transaction created by createTransaction.
Merging this PR will improve performance by ×30
Performance Changes
Comparing |
f37b4e1 to
4cc03b8
Compare
|
Hi @MarkusLund, thanks for the pull request. Before we merge it though, could you sign the CLA? |
|
The PR looks good, I think it can be merged when the CLA is signed and the one minor comment I left is addressed. |
4cc03b8 to
70e179c
Compare
|
CLA signed, @jacek-prisma 👍 |
| }, | ||
|
|
||
| async commit() { | ||
| if (useMutexForCommitRollback) { |
There was a problem hiding this comment.
useMutexForCommitRollback is now always true, so we can remove the parameter and the unreachable branches
| } | ||
| } | ||
|
|
||
| describe('with mutex (the fix)', () => { |
There was a problem hiding this comment.
probably don't need the nested describe here
…NPROG error (#29141) Cleanup of #29119 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Fixed race condition in MSSQL transaction handling where commit() or rollback() could fail when queries are in progress. * **Tests** * Added comprehensive test suite for transaction serialization to validate proper operation ordering and error handling. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Markus Haave Lund <markus.lund@bekk.no>
|
Included in #29141 |
Description
Fix race condition in
MssqlTransactionwherecommit()orrollback()can be called while a query is still in progress, causing the mssql driver to throwEREQINPROGerror.Problem
The mssql driver throws
EREQINPROG("Can't rollback transaction. There is a request in progress.") whencommit()orrollback()is invoked while a query is executing. This commonly occurs when a transaction times out during an in-flight query.In the current implementation:
performIO()acquires a mutex before executing queriescommit()androllback()do not acquire the mutexThis allows
commit()/rollback()to race with active queries.Solution
Modified
commit()androllback()to acquire the same mutex thatperformIO()uses. This ensures they wait for any active query to complete before executing.Changes
packages/adapter-mssql/src/mssql.ts: Added mutex acquisition tocommit()androllback()methodspackages/adapter-mssql/src/mssql.test.ts: Added unit tests validating the mutex serialization behaviorFixes #28994
Summary by CodeRabbit
Bug Fixes
Tests