fix(adapter-mariadb): release pooled connections and harden transaction cleanup#29612
fix(adapter-mariadb): release pooled connections and harden transaction cleanup#29612andychinghk01 wants to merge 1 commit into
Conversation
…on cleanup Fixes prisma#28964 The MariaDB adapter previously called `mariadb.Connection#end()` to dispose of a transaction connection. For a `PoolConnection` `end()` is aliased to `release()`, so in practice it does return the connection to the pool — but the intent is ambiguous, and the same code path is reachable with a plain `mariadb.Connection` (e.g. in tests), where `end()` permanently closes the connection. The transaction failure path also removed the connection's `error` listener *after* releasing the connection and without a try/finally, so a throw during teardown would leak the listener onto the next caller. Changes: * Introduce a small `releaseConnection()` helper that prefers `PoolConnection#release()` and falls back to `Connection#end()`. * Use it from `MariaDbTransaction#commit` and `#rollback`. * In `startTransaction`'s catch path, detach the error listener before releasing the connection and wrap the release in try/finally so the connection is always returned to the pool. Tests: * Cover `release()` vs `end()` fallback. * Cover listener cleanup on `commit`. * Cover listener cleanup on `startTransaction` failure. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Copilot seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
Summary by CodeRabbit
WalkthroughThe MariaDB adapter now properly returns transaction connections to the connection pool instead of permanently closing them. A new ChangesTransaction connection pool management
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 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)
✨ Simplify code
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 |
Summary
Fixes #28964.
The MariaDB adapter previously called
mariadb.Connection#end()to dispose of a transaction connection. For aPoolConnectionend()happens to be aliased torelease(), so in practice it does return the connection to the pool — but the intent is ambiguous, and the same code path is reachable with a plainmariadb.Connection(e.g. in tests), whereend()permanently closes the connection. The transaction failure path also removed the connection'serrorlistener after releasing the connection and without atry/finally, so a throw during teardown would leak the listener onto the next caller.Changes
releaseConnection()helper that prefersPoolConnection#release()and falls back toConnection#end().MariaDbTransaction#commitand#rollback.startTransaction's catch path, detach theerrorlistener before releasing the connection and wrap the release intry/finallyso the connection is always returned to the pool, even if cleanup throws.Tests
Added unit tests in
packages/adapter-mariadb/src/mariadb.test.ts:release()is used for pool connections;end()fallback for non-pool connections.errorlistener is detached oncommit.errorlistener is detached and the connection is released onstartTransactionfailure.All 26 adapter unit tests pass (
pnpm --filter @prisma/adapter-mariadb test).Out-of-band verification
I also ran an end-to-end harness with Docker (
mariadb:10.11) covering:connectionLimit=100, 100 concurrent transactions → 100 idle conns after release ✅connectionLimit=100→ capped at 100, no leak ✅idleTimeout=10s→ pool drains tominimumIdleafter the window ✅Closes #28964