[PR #5684] fix(jwt): add mutex lock to JWT #14404

Closed
opened 2026-04-13 09:27:28 -05:00 by GiteaMirror · 0 comments
Owner

Original Pull Request: https://github.com/better-auth/better-auth/pull/5684

State: closed
Merged: No


This PR adds a mutex lock to ensure concurrency safety for JWT.

This PR fixes #5663.


Summary by cubic

Adds application-level concurrency control for JWK creation to prevent duplicate keys when JWKS and token signing are called in parallel. Fixes #5663.

  • Bug Fixes

    • Serialize JWK creation with an app-level mutex.
    • Added adapter.getOrCreateLatestKey and use it in JWKS and signJWT paths.
    • Ensures only one latest key exists under concurrent requests.
  • Refactors

    • Split key generation into generateJwkData; createJwk now delegates to it.
    • Updated jwt/index and sign.ts to use the new adapter flow.
    • Added tests for concurrent JWKS, token signing, signJWT, and mixed scenarios.

Written for commit 5e3eb75a81. Summary will update automatically on new commits.

**Original Pull Request:** https://github.com/better-auth/better-auth/pull/5684 **State:** closed **Merged:** No --- This PR adds a mutex lock to ensure concurrency safety for JWT. This PR fixes #5663. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds application-level concurrency control for JWK creation to prevent duplicate keys when JWKS and token signing are called in parallel. Fixes #5663. - **Bug Fixes** - Serialize JWK creation with an app-level mutex. - Added adapter.getOrCreateLatestKey and use it in JWKS and signJWT paths. - Ensures only one latest key exists under concurrent requests. - **Refactors** - Split key generation into generateJwkData; createJwk now delegates to it. - Updated jwt/index and sign.ts to use the new adapter flow. - Added tests for concurrent JWKS, token signing, signJWT, and mixed scenarios. <sup>Written for commit 5e3eb75a811e839d30416bc8ab36771281307078. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. -->
GiteaMirror added the pull-request label 2026-04-13 09:27:28 -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#14404