Repository navigation
Auth SQLite: WAL, busy timeout, BEGIN IMMEDIATE, database rate limit; 503 not false 401 (#927) - #934
Merged
Merged
Conversation
…IN IMMEDIATE, database rate limit, 503 on storage errors (#927) - Open auth.sqlite 0600 (refuse a non-private file) with a 2 s busy timeout, WAL and synchronous=FULL, mirroring the store and audit. - Better Auth transactions begin IMMEDIATE. Its sign-up reads, hashes, then writes; under WAL a deferred transaction failed with SQLITE_BUSY_SNAPSHOT (errcode 517) whenever another process committed during the hash: reproduced 40/40 create-user failures beside a steady writer, 0/40 after. - rateLimit.storage 'database' by default; migrate creates the rateLimit table and activation refuses a database without it. - authorize() answers 503 auth_unavailable (Retry-After: 1) on a storage failure instead of a false 401; a missing or forged session stays 401. - Tests: two serving child processes share one sign-in budget (10 x 401, then 429); create-user beside a continuously committing server; 503 vs 401. - The private-requests proof gives its third fixture run fresh data and clears rateLimit before the MCP runners, since the budget now persists. - Docs: auth README/SECURITY/CHANGELOG, EXTENSIONS, RESILIENCE backups (-wal/-shm), proof README. Co-Authored-By: Claude Opus 5.5 <[email protected]>
jimhoyd
enabled auto-merge (squash)
September 29, 2026 16:54
jimhoyd
added a commit
that referenced
this pull request
Sep 29, 2026
… busy-timeout 503 in the cross-connection transfer race Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Sep 29, 2026
Merged
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 first two items of #927, which also fix a bug that affects single-server sites.
Found
auth.sqlitewas opened with neither. A second process writing (for exampleurlcode-auth create-userbeside a running server) got "database is locked" at once, andauthorize()turned that into a false 401.begin. Sign-up reads, hashes the password with scrypt, then inserts.SQLITE_BUSY_SNAPSHOT(517), which the busy timeout does not retry.Changes (
packages/auth/src/auth.ts)openAuthDatabase(), used by the server and the CLI:allowExtensionis off, the busy timeout is 2000 ms, andtrusted_schema=OFF,journal_mode=WALandsynchronous=FULLare set.BEGIN IMMEDIATE: a small documentedDatabaseSyncsubclass rewrites exactlybegintoBEGIN IMMEDIATE, so Better Auth keeps its own dialect. The cost: the write lock is held for the length of the password hash, and other processes wait for it up to the timeout instead of failing.rateLimit.storage: 'database'is the default, so the limit is shared across processes; an operator can override it.migratecreates therateLimittable, and activation refuses a database without it.authorize(): a Better Auth 4xx or null stays 401. Any storage or I/O error now answers503 {"error":"auth_unavailable"}withRetry-After: 1and no detail.Evidence (macOS, Node 26)
auth.sqlite, with 12 sign-ins alternated between them, give 10 × 401 then 429.rateLimittable is refused, a migrated file is 0600 and in WAL mode, and a 0644 file is refused.rateLimitbefore the MCP runners, and gives the third fixture run fresh data, because counts now persist across processes.npm run verifypasses (core 1226, auth 8, store 172, proof 12, proof:authjs 13, ecosystem 12);npm run test:packagepasses.Existing sites
Run
npx urlcode-auth migrateonce to create therateLimittable, andchmod 600 data/auth.sqliteif the file was created 0644. There is no compatibility path, since the owner is the only user.Follow-ups
🤖 Generated with Claude Code