Repository navigation
Commit cb27f62
fix(server): stop syncing the SQLite WAL on every commit (#1722)
## Problem
SQLite runs at its default `synchronous = FULL`, so every commit waits for an fsync.
The one connection commits on the main thread, so a slow disk freezes the whole server.
On `ugrindtime`, disk writes waited about 224 ms each, and clients dropped for 2 minutes.
Upstream tracks the same stall as `pingdotgg#15707`, with no fix pull request yet.
## Change
- **Setting:** `PRAGMA synchronous = NORMAL`
- **New file:** `SqliteSynchronous.fork.ts`
- **Hook:** one line in `Sqlite.ts`
- **WAL sync:** at checkpoints, not per commit
### Durability
- **Power loss:** can drop the last commits
- **Consistency:** the database stays intact
- **App crash:** loses nothing
### Live measurements
- **Commits:** about 7.7 per second
- **Syncs per commit:** 1 before, 0 after
- **Checkpoints:** about 1 every 6 s
### Not changed
A larger `wal_autocheckpoint` saved only 11% of bytes in a 3-minute replay of live WAL pages.
It was left out.
## Scope and approval
Refs #1720.
The maintainer chose this fix after the stall analysis.
## Verification
- **New test:** WAL mode with `synchronous` 1
- **Mutation check:** fails with 2 without the hook
- **Persistence tests:** 4 of 4 pass
- **Typecheck:** `apps/server`, exit 0
- **Fork CI:** `vp run fork:ci`, exit 0
- **Not checked:** a live server on this build
Claude Code, claude-opus-5-5.
## Fork trailers
Fork-Domain: upstream-fixes
Fork-Tier: bugfix
Fork-Upstreamable: yes
Co-authored-by: donjor <[email protected]>1 parent ba8335a commit cb27f62
3 files changed
Lines changed: 44 additions & 0 deletions
File tree
- apps/server/src/persistence
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| 35 | + | |
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
0 commit comments