Skip to content

fix(adapter-mssql): acquire mutex in commit/rollback to prevent EREQINPROG error#29141

Merged
jacek-prisma merged 2 commits intomainfrom
fix/adapter-mssql-race-condition
Feb 6, 2026
Merged

fix(adapter-mssql): acquire mutex in commit/rollback to prevent EREQINPROG error#29141
jacek-prisma merged 2 commits intomainfrom
fix/adapter-mssql-race-condition

Conversation

@jacek-prisma
Copy link
Copy Markdown
Contributor

@jacek-prisma jacek-prisma commented Feb 6, 2026

Cleanup of #29119

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.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 6, 2026

Walkthrough

Implements mutex-based serialization in MssqlTransaction to prevent race conditions where commit() or rollback() operations could fail if a query is in progress. Adds a comprehensive test suite validating that commit, rollback, and query operations are properly serialized, including error handling scenarios.

Changes

Cohort / File(s) Summary
Test Suite
packages/adapter-mssql/src/mssql.test.ts
Adds tests for MssqlTransaction mutex serialization covering: rollback/commit waiting for in-flight queries, EABORT error handling, non-EABORT error propagation, and ordering of concurrent queries followed by commit operations.
Implementation
packages/adapter-mssql/src/mssql.ts
Introduces mutex locking around commit() and rollback() methods in MssqlTransaction to serialize operations with in-flight queries, preventing concurrent transaction state modifications.
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the main change: acquiring a mutex in commit/rollback operations to prevent EREQINPROG errors in the mssql adapter.

✏️ 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
  • Commit unit tests in branch fix/adapter-mssql-race-condition

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/adapter-mssql/src/mssql.ts (1)

81-90: ⚠️ Potential issue | 🔴 Critical

Bug: double error wrapping in performIO override.

super.performIO (lines 50–63) already catches errors and calls this.onError(e), which throws a DriverAdapterError. The catch block here (line 85–86) catches that already-wrapped DriverAdapterError and feeds it through this.onError(e) a second time, applying convertDriverError to a DriverAdapterError instead of a raw mssql error. Remove the catch block—the finally alone is sufficient to release the mutex, and the error will propagate correctly.

Proposed fix
   async performIO(query: SqlQuery): Promise<ArrayModeResult> {
     const release = await this.#mutex.acquire()
     try {
       return await super.performIO(query)
-    } catch (e) {
-      this.onError(e)
     } finally {
       release()
     }
   }

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 6, 2026

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.52 MB (0%)
packages/client/prisma-client-0.0.0.tgz 26.58 MB (+0.01% 🔺)
packages/cli/prisma-0.0.0.tgz 12.36 MB (0%)
packages/bundle-size/da-workers-libsql/output.tgz 1.24 MB (0%)
packages/bundle-size/da-workers-neon/output.tgz 1.3 MB (0%)
packages/bundle-size/da-workers-pg/output.tgz 1.29 MB (0%)
packages/bundle-size/da-workers-planetscale/output.tgz 1.24 MB (0%)
packages/bundle-size/da-workers-d1/output.tgz 1.21 MB (0%)

@jkomyno jkomyno added this to the 7.4.0 milestone Feb 6, 2026
@jacek-prisma jacek-prisma merged commit 6a98c8f into main Feb 6, 2026
254 checks passed
@jacek-prisma jacek-prisma deleted the fix/adapter-mssql-race-condition branch February 6, 2026 13:29
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.

3 participants