Flaky E2E: write conflict on step/guide row locks under parallel runs #43

Closed
opened 2026-11-02 18:50:46 +01:00 by miko · 1 comment
Owner

Problem

Running the full Playwright suite in parallel, e2e/authoring.spec.ts or e2e/access.spec.ts fails roughly every other run. The server logs:

DriverAdapterError: TransactionWriteConflict
Transaction failed due to a write conflict or a deadlock. Please retry your transaction

The error comes from a queryRaw lock (lockStep / lockGuide, SELECT … FOR UPDATE) while adding the annotated step and its image. It reproduces with e2e/categories.spec.ts excluded, so it predates #41.

Likely cause to check: MariaDB's snapshot isolation (error 1020, "record has changed since last read") when a transaction reads before taking its FOR UPDATE lock, or when two requests touch the same rows (e.g. the shared E2E category).

Acceptance criteria

  • Root cause found (which action, which read before which lock)
  • Either fixed in the action (lock first, or retry on write conflict) or the tests no longer contend
  • Full E2E suite passes repeatedly in parallel
## Problem Running the full Playwright suite in parallel, `e2e/authoring.spec.ts` or `e2e/access.spec.ts` fails roughly every other run. The server logs: ``` DriverAdapterError: TransactionWriteConflict Transaction failed due to a write conflict or a deadlock. Please retry your transaction ``` The error comes from a `queryRaw` lock (`lockStep` / `lockGuide`, `SELECT … FOR UPDATE`) while adding the annotated step and its image. It reproduces with `e2e/categories.spec.ts` excluded, so it predates #41. Likely cause to check: MariaDB's snapshot isolation (error 1020, "record has changed since last read") when a transaction reads before taking its `FOR UPDATE` lock, or when two requests touch the same rows (e.g. the shared E2E category). ## Acceptance criteria - [ ] Root cause found (which action, which read before which lock) - [ ] Either fixed in the action (lock first, or retry on write conflict) or the tests no longer contend - [ ] Full E2E suite passes repeatedly in parallel
Author
Owner

Root cause: MySQL 8.4 (not MariaDB) gap-lock deadlocks (1213, which Prisma reports as TransactionWriteConflict). Under REPEATABLE READ, deleting the Step Lines of two empty steps took the same index gap lock, and each insert then waited for the other. A second risk: saveStep locked guide→step while image and annotation actions locked step→guide. Fixed in #46: READ COMMITTED for all transactions, and one lock order (the guide's lock first; lockStep removed). See ADR-0013. The parallel suite passed 14 times in a row with no retries.

Root cause: MySQL 8.4 (not MariaDB) gap-lock deadlocks (1213, which Prisma reports as TransactionWriteConflict). Under REPEATABLE READ, deleting the Step Lines of two empty steps took the same index gap lock, and each insert then waited for the other. A second risk: saveStep locked guide→step while image and annotation actions locked step→guide. Fixed in #46: READ COMMITTED for all transactions, and one lock order (the guide's lock first; lockStep removed). See ADR-0013. The parallel suite passed 14 times in a row with no retries.
miko closed this issue 2026-11-02 19:29:26 +01:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MassiveDynamic/kataba#43
No description provided.