[PR #8971] fix(mysql): handle race conditions for concurrent inserts #25236

Open
opened 2026-04-15 22:46:51 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8971
Author: @howlettt
Created: 4/5/2026
Status: 🔄 Open

Base: main ← Head: fix/mysql-inserted-id


📝 Commits (6)

  • 307f296 fix(kysely-mysql): handle race conditions for concurrent inserts
  • eeb302b chore: remove unneeded Number()
  • 77f4069 fix(drizzle-mysql): handle race conditions for concurrent inserts
  • 1ea02fa Merge branch 'main' into fix/mysql-inserted-id
  • 2e923a1 Add changeset
  • 7f59936 Fix changeset

📊 Changes

4 files changed (+58 additions, -4 deletions)

View changed files

➕ .changeset/famous-cloths-divide.md (+7 -0)
📝 packages/drizzle-adapter/src/drizzle-adapter.ts (+16 -1)
📝 packages/kysely-adapter/src/kysely-adapter.ts (+12 -3)
📝 packages/test-utils/src/adapter/suites/basic.ts (+23 -0)

📄 Description

Use the returned ID from MySQL when available to avoid race conditions for concurrent inserts.
Took the test from the closed PR https://github.com/better-auth/better-auth/pull/6634

Fixes #8867


Summary by cubic

Fixes MySQL concurrent insert race conditions by selecting newly inserted rows by id in @better-auth/kysely-adapter and @better-auth/drizzle-adapter. Also updates instrumentation to use route templates and hardens password checks.

  • Bug Fixes

    • @better-auth/kysely-adapter (MySQL): use executeTakeFirst() to read insertId; if present, select by id; otherwise fall back.
    • @better-auth/drizzle-adapter (MySQL): prefer $returningId(); after execute(), if an id is returned, reselect by id; otherwise fall back.
    • Instrumentation: endpoint spans set http.route to route templates; plugin onRequest/onResponse spans no longer include the route.
    • Passwords: checkPassword now returns INVALID_PASSWORD for all failures to prevent credential/account enumeration; tests added (2FA and concurrent-create).
  • Refactors

    • Remove unnecessary Number() cast when handling MySQL insertId.

Written for commit 7f59936720. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/8971 **Author:** [@howlettt](https://github.com/howlettt) **Created:** 4/5/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/mysql-inserted-id` --- ### 📝 Commits (6) - [`307f296`](https://github.com/better-auth/better-auth/commit/307f296f5299996905371eae05066c838b1ead87) fix(kysely-mysql): handle race conditions for concurrent inserts - [`eeb302b`](https://github.com/better-auth/better-auth/commit/eeb302b0e5e7536d045545b4cafcf78f46831ed0) chore: remove unneeded Number() - [`77f4069`](https://github.com/better-auth/better-auth/commit/77f4069d35c522032755b8e3fc5cde4c27f2a6f6) fix(drizzle-mysql): handle race conditions for concurrent inserts - [`1ea02fa`](https://github.com/better-auth/better-auth/commit/1ea02fa81e1dce6b3a318f466c9dcfce7c497f39) Merge branch 'main' into fix/mysql-inserted-id - [`2e923a1`](https://github.com/better-auth/better-auth/commit/2e923a1fbc3755da2b1119002378a31ea9436056) Add changeset - [`7f59936`](https://github.com/better-auth/better-auth/commit/7f59936720e052eaed8c29299c907a007c4846f3) Fix changeset ### 📊 Changes **4 files changed** (+58 additions, -4 deletions) <details> <summary>View changed files</summary> ➕ `.changeset/famous-cloths-divide.md` (+7 -0) 📝 `packages/drizzle-adapter/src/drizzle-adapter.ts` (+16 -1) 📝 `packages/kysely-adapter/src/kysely-adapter.ts` (+12 -3) 📝 `packages/test-utils/src/adapter/suites/basic.ts` (+23 -0) </details> ### 📄 Description Use the returned ID from MySQL when available to avoid race conditions for concurrent inserts. Took the test from the closed PR https://github.com/better-auth/better-auth/pull/6634 Fixes #8867 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes MySQL concurrent insert race conditions by selecting newly inserted rows by id in `@better-auth/kysely-adapter` and `@better-auth/drizzle-adapter`. Also updates instrumentation to use route templates and hardens password checks. - **Bug Fixes** - `@better-auth/kysely-adapter` (MySQL): use `executeTakeFirst()` to read `insertId`; if present, select by id; otherwise fall back. - `@better-auth/drizzle-adapter` (MySQL): prefer `$returningId()`; after `execute()`, if an id is returned, reselect by id; otherwise fall back. - Instrumentation: endpoint spans set `http.route` to route templates; plugin `onRequest`/`onResponse` spans no longer include the route. - Passwords: `checkPassword` now returns `INVALID_PASSWORD` for all failures to prevent credential/account enumeration; tests added (2FA and concurrent-create). - **Refactors** - Remove unnecessary `Number()` cast when handling MySQL `insertId`. <sup>Written for commit 7f59936720e052eaed8c29299c907a007c4846f3. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-15 22:46:51 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#25236