You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The initial OAuth resource SELECT can fail with CONNECT_TIMEOUT before the connection is established. Retry that exact resource-identifier lookup once outside a transaction, so a cold connection failure can recover during auth startup.
The retry requires matching CONNECT_TIMEOUT code and errno values and preserves the existing adapter behavior for other reads and transaction phases.
Validation:
47 focused connection and resource-adapter controls passed.
The original 67 actual Node24 auth journeys passed on commit44494251. Their executed bundle is byte-identical after current-main integration; no new Node67 execution is claimed for this head.
Canonical local verification at 72e67e2: 7,478 passed, 0 failed, 0 skipped, actual exit0. Final Bun/Node checks verified all eight owned database identities, 42 migrations, canonical catalog and idle connections.
No actionable comments were generated in the recent review.
Walkthrough
The change adds a guarded, single retry for initial database connection timeouts. It applies the retry only to exact OAuth resource lookups outside adapter transactions and wraps the Drizzle adapter during Better Auth setup.
Changes: OAuth Resource Connection Retry
Layer / File(s)
Summary
Recognize and retry initial connection timeouts packages/db/src/connection-retry.ts, packages/db/src/index.ts, packages/db/tests/connection-retry.test.ts
Adds and exports a helper that recognizes eligible connection timeouts and retries an operation once when the retry phase is active. Tests cover error inspection, retry conditions, and separate retry budgets for concurrent calls.
Scope retries to OAuth resource lookups apps/web/src/lib/auth/resource-adapter.ts, apps/web/tests/lib/auth/resource-adapter.test.ts
Adds an adapter wrapper that retries only matching resource reads outside transactions. Tests cover excluded query shapes, mutations, transactions, and concurrent reads.
Apply the wrapper during Better Auth setup apps/web/src/lib/auth/server.ts, apps/web/tests/lib/auth/resource-adapter.test.ts
Wraps the Drizzle adapter with the resource URL. Tests cover initialization with a configured resource model, adapter schema checks, and behavior without an OAuth provider.
sequenceDiagram
participant BetterAuth
participant withOAuthResourceConnectionRetry
participant retryInitialDatabaseConnection
participant DBAdapter
BetterAuth->>withOAuthResourceConnectionRetry: findOne with the configured resource query
withOAuthResourceConnectionRetry->>retryInitialDatabaseConnection: run matching read outside a transaction
retryInitialDatabaseConnection->>DBAdapter: findOne
DBAdapter-->>retryInitialDatabaseConnection: timeout or result
retryInitialDatabaseConnection->>DBAdapter: retry once if retry conditions still hold
DBAdapter-->>retryInitialDatabaseConnection: result
retryInitialDatabaseConnection-->>withOAuthResourceConnectionRetry: return result
withOAuthResourceConnectionRetry-->>BetterAuth: return result
Loading
Merge Risk: Minimal · up to 72e67
The change adds a narrow, single retry for the initial OAuth resource lookup when the database connection times out. Other reads, writes and transactions keep their existing behavior. No actionable merge-blocking risk was found. Confirm that public CI passes before merging.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the fix and its scope: retrying the initial OAuth resource connection in auth. The changeset adds a retry wrapper for the OAuth resource lookup and a connection-retry helper, so the ti…
Description check
The description states the purpose: the initial OAuth resource SELECT can fail with CONNECT_TIMEOUT, and the change retries that exact lookup once outside a transaction. It also names the matching cod…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the fix and its scope: retrying the initial OAuth resource connection in auth. The changeset adds a retry wrapper for the OAuth resource lookup and a connection-retry helper, so the title matches the main change. It uses the conventional commit prefix and is specific.
Full details: Description check
Explanation
The description states the purpose: the initial OAuth resource SELECT can fail with CONNECT_TIMEOUT, and the change retries that exact lookup once outside a transaction. It also names the matching code and errno checks, which the changeset implements. It includes validation notes. The description is specific to this changeset.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Reviewing files that changed from the base of the PR and between d1b1545 and 72e67e2.
Files selected for processing: 6
apps/web/src/lib/auth/resource-adapter.ts
apps/web/src/lib/auth/server.ts
apps/web/tests/lib/auth/resource-adapter.test.ts
packages/db/src/connection-retry.ts
packages/db/src/index.ts
packages/db/tests/connection-retry.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
area: authSign-in, sessions, passkeys, OAutharea: databaseSchema, migrations, queries, seedarea: webThe Next.js app and its UItestsTest coverage and test infrastructure
1 participant
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The initial OAuth resource SELECT can fail with CONNECT_TIMEOUT before the connection is established. Retry that exact resource-identifier lookup once outside a transaction, so a cold connection failure can recover during auth startup.
The retry requires matching CONNECT_TIMEOUT code and errno values and preserves the existing adapter behavior for other reads and transaction phases.
Validation:
No schema migration is required.