Repository navigation
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 configuration
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 |
|
izadoesdev
left a comment
There was a problem hiding this comment.
Thanks, the fail-fast idea is sound: Better Auth's findSession does not catch secondary-storage errors, so this turns a 5s x 3 retry stall into a 1.5s failure. Two things before it can merge:
- Race on the failure window (Greptile's P1, still present at
packages/redis/redis.ts:255): a success resetsauthCacheFailFastUntil = 0unconditionally, so an older command that succeeds after a newer one failed clears the fresh 5s window. InrunAuthCacheRedisCommand, captureconst windowAtStart = authCacheFailFastUntilbefore the call, and on success only reset itif (authCacheFailFastUntil === windowAtStart). - Rebase onto
staging: it now conflicts inpackages/auth/src/auth.ts(Better Auth 1.7.5 landed and the SSO plugin was removed) and inpackages/redis/000-redis.test.ts(formatting only).
Locally at this head the redis tests pass 8/8, the auth test passes and tsc is clean, so after these two changes it should be close.
4f38c6f to
67fe156
Compare
Requested change applied in the rework pushed today: the fail-fast window now expires by time only, so a late success cannot clear it.
d6e7bd3
into
databuddy-analytics:staging
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
runAuthStorageCommand, which rejects immediately for 5 seconds after a recent Redis failure and enforces a 1500ms operation deadline.Written for commit 67fe156. Summary will update on new commits.