fix(auth): fail-fast Better Auth session Redis reads - #692
Conversation
|
@Fraol-D is attempting to deploy a commit to the Databuddy OSS Team on Vercel. A member of the Team first needs to authorize it. |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
Greptile SummaryThis PR adds a dedicated timeout and fail-fast circuit for Better Auth’s Redis secondary storage.
Confidence Score: 4/5The PR needs a concurrency-safe breaker update before merging because an older successful operation can erase a newer Redis failure and defeat the intended fail-fast behavior. The shared auth-cache failure deadline is cleared by any success without accounting for overlapping command order, allowing subsequent session reads to re-enter the slow Redis path immediately after a failure. Files Needing Attention: packages/redis/redis.ts Important Files Changed
Sequence DiagramsequenceDiagram
participant A as Auth command A
participant B as Auth command B
participant R as Redis
participant F as Shared fail-fast deadline
A->>R: Start operation
B->>R: Start operation
R-->>B: Failure
B->>F: Set deadline to now + 5s
R-->>A: Success
A->>F: Reset deadline to 0
Note over F: Recent failure is forgotten
B->>F: Next auth read checks deadline
F-->>B: Execute Redis operation instead of failing fast
Reviews (1): Last reviewed commit: "fix(auth): fail-fast Better Auth session..." | Re-trigger Greptile |
| AUTH_CACHE_OPERATION_DEADLINE_MS, | ||
| `Auth cache operation exceeded ${AUTH_CACHE_OPERATION_DEADLINE_MS}ms` | ||
| ); | ||
| authCacheFailFastUntil = 0; |
There was a problem hiding this comment.
Concurrent success clears failure
If two auth-cache commands overlap and the newer command fails before the older one succeeds, the unconditional reset on success erases the newer five-second failure window. Subsequent session reads then attempt Redis and can incur the full 1.5-second deadline instead of failing fast.
Description
This PR fixes Better Auth session Redis reads so they fail fast when Redis is unavailable, preventing repeated session lookups from waiting for the full Redis timeout.
The change adds a dedicated auth-cache fail-fast path with a 5-second failure window and a 1500ms operation deadline. The auth failure state is kept independent from the existing link-cache failure state, so a failure in one does not affect the other.
Tests were added to verify the fail-fast behavior, independent failure windows, and recovery/reset behavior.
Slice
packages/auth,packages/redisChecklist
stagingand does not include another unmerged PR unless it is named above.staging; after it closes, this branch will not be reused for another change.Summary by cubic
Makes Better Auth session reads fail fast when Redis is down, so requests don't wait out the full timeout on every session lookup.
Bug Fixes
runAuthCacheCommand, which rejects immediately for 5 seconds after a recent Redis failure and enforces a 1500ms operation deadline.createAuthSecondaryStoragewith tests covering the fail-fast behavior.Written for commit 4f38c6f. Summary will update on new commits.