Skip to content

fix(db): stop failing requests with 500 when SQLite waits on a slow disk - #319

Merged
LouisHaftmann merged 2 commits into
devfrom
fix/sqlite-writer-slow-disk
Nov 23, 2026
Merged

LouisHaftmann merged 2 commits into
devfrom
fix/sqlite-writer-slow-disk

Conversation

@LouisHaftmann

@LouisHaftmann LouisHaftmann commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

📝 Summary

On a disk slower than the incoming uploads, requests failed with HTTP 500. Parts pile up in the page cache faster than the disk writes them back, and every SQLite commit has to wait behind that backlog. The queue for the single writer connection grew past sqlx's 30 s default acquire timeout, so requests failed with Connection pool timed out. #318 reports the same slow statements and connection waits.

The SQLite pools now wait up to 10 minutes for a connection. A request on a slow disk takes longer, but it no longer fails. The upload path does not change, so fast disks keep their speed.

 SqlitePoolOptions::new()
     .test_before_acquire(false)
+    .acquire_timeout(10 min)   # was sqlx's default of 30 s

An earlier version of this PR synced each Part to disk before confirming it. That also removed the failures, but it cut NVMe upload speed from ~4 to ~1.5 GiB/s. Here is how the alternatives compared on a disk throttled to 40 MB/s:

Variant Failed requests Slowest request Upload speed on NVMe
v10.0.1 29–54 53 s ~4.0 to 4.6 GiB/s
Sync each Part before confirming it 0 n/a ~1.5 GiB/s
Sync the filesystem after 1 GiB of unsynced data 0 39 s not measured (~1.7 GiB/s at a 512 MiB budget)
Sync the filesystem after 2 GiB of unsynced data 15 51 s not measured
Wait for the writer (this PR) 0 35–40 s same as v10.0.1

✅ Verification

Load: 16 parallel uploads of 128 MiB per round, then restores, 3 rounds. The container's writes are throttled to 40 MB/s (--device-write-bps), with SQLite and the filesystem driver.

  • Before (v10.0.1 source): 29 to 54 failed requests (Connection pool timed out). Up to 15 of 16 uploads failed in a round.
    After: 0 failed requests. The slowest single request took 39 s.
  • cargo +nightly fmt --check, cargo clippy --all-targets --locked and cargo test (SQLite + filesystem) all pass.

Benchmark (examples/benchmark.rs, NVMe). Base is the published 10.0.1 image, which is built from the same source as dev. The differences between the two columns are within the noise between runs:

Metric base fix
Upload (8 × 128 MiB, parallel) 4352 MiB/s 4889 MiB/s
First download (merge on read) 7007 MiB/s 5421 MiB/s
Later download (merged) 2612 MiB/s 3331 MiB/s
Lookups per second (64 concurrent) 30597 34565
Lookup p99 15.0 ms 4.4 ms
Small save+restore per second 1010 1062
Peak memory 103.6 MiB 101.5 MiB

🔗 Issues

Related to #318. That issue is about memory growth, which this PR does not fix.

💥 Merge danger

Door: two-way

Blast Radius: sqlite-only

Only the SQLite pools change. If the database really hangs, requests now wait up to 10 minutes instead of failing after 30 s. Postgres and MySQL do not change.

⚠️ Needs attention

  • On a disk this slow, a request can still take ~40 s. A client with a shorter timeout than that still fails, on the client side.

🤖 Generated with Claude Code

On a disk slower than the incoming uploads, parts piled up in the page
cache and every SQLite commit waited behind that writeback backlog. The
single writer connection then stayed busy past sqlx's 30 s acquire
timeout and requests failed with "Connection pool timed out".

The filesystem driver now syncs each part before confirming it, so
uploads run at disk speed and the backlog stays bounded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://fix-sqlite-writer-slow-disk-docs-gha-cache-server.louis-haftmann.workers.dev (commit 60ee2fe)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://a6c6a593-docs-gha-cache-server.louis-haftmann.workers.dev 60ee2fe 2026-11-23T11:17:01.905Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://ab6aa857-docs-gha-cache-server.louis-haftmann.workers.dev 4232829 2026-11-23T10:44:47.700Z Visit the dashboard ↗

Syncing each part halved upload speed on fast disks. The 500s came from
sqlx's 30 s acquire timeout, not from the backlog itself: with a 10 min
timeout, requests on a slow disk wait up to ~40 s and none fail, and the
upload path stays as fast as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@LouisHaftmann LouisHaftmann changed the title fix(storage): stop failing uploads with 500 on slow disks fix(db): stop failing requests with 500 when SQLite waits on a slow disk Nov 23, 2026
@LouisHaftmann
LouisHaftmann merged commit 58b9434 into dev Nov 23, 2026
28 of 29 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