Skip to content

test(beyondleetcode): C43b multi-user fixture stops timing out on the shared database - #192

Merged
GauranshMathur merged 2 commits into
mainfrom
C43b-multi-db-timeout
Oct 16, 2026
Merged

GauranshMathur merged 2 commits into
mainfrom
C43b-multi-db-timeout

Conversation

@GauranshMathur

@GauranshMathur GauranshMathur commented Oct 16, 2026 •

Copy link
Copy Markdown
Owner

Test-only fix for the "Operation has timed out" flake on the shared Multi-user test database (C43b). Only src/routes/users/multi-fixture.ts and playwright.config.ts change; no production code.

Root cause

Prisma's "Operation has timed out" (P1008) is SQLITE_BUSY. Two causes stack:

  1. libSQL's busy timeout defaults to 0, and createDb does not set one, so a write that meets another process's lock fails at once.
  2. Prisma's libSQL adapter opens transactions as deferred (read, then write). SQLite refuses a read-to-write upgrade at once, whatever the timeout, when another connection holds the write lock. A busy timeout alone does not fix this (reproduced: 3 processes x 40 ensureLearner calls still failed). Better Auth also swallows the error and throws "Failed to create user".

Fix

  • multi-fixture.ts: the fixture opens its own client with a 10 s busy timeout, counts P1008 errors via a Prisma query extension, and retryWhenBusy re-runs ensureLearner / signIn (at most 4 attempts, jittered) only when a P1008 happened inside. Anything else (unique constraint, bad password) throws at once.
  • playwright.config.ts: the 4174 test database is put in WAL mode (stored in the file). The server's own client (timeout 0, deferred transactions) was also failing sign-in in the e2e (P1008 in the server log), which the fixture cannot reach.

Results (flock .../BeyondLeetcode.worktrees/.playwright.lock bunx playwright test --project=e2e-multi, workers 4)

  • Before WAL (fixture fix only): 6 of 10 runs passed; the 4 failures were all signin.multi.e2e.ts:353 where the server's own sign-in hit P1008.
  • Final: 10 of 10 runs, 44 passed each; no P1008 in any log.
  • Full bunx playwright test: 95 passed. biome check clean.

Follow-up (not done here, production code)

The app has the same exposure under concurrent writers: src/lib/server/db.ts could set a timeout and the adapter could begin transactions immediately. Worth a card.

Reviews

Self-review done. Codex second opinion skipped: test-only diff outside runner/learning/.github (board.md allows it). No security review for this card.

🤖 Generated with Claude Code

GauranshMathur and others added 2 commits October 16, 2026 14:31
…lock and retries a busy transaction

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…er test database

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@GauranshMathur
GauranshMathur marked this pull request as ready for review October 16, 2026 14:51
@GauranshMathur
GauranshMathur merged commit ae14f61 into main Oct 16, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant