Repository navigation
fix(db): stop failing requests with 500 when SQLite waits on a slow disk - #319
Merged
Merged
Conversation
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>
🚀 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 deploymentPreview Deployments by commit
|
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>
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.
📝 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 sAn 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:
✅ 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.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 --lockedandcargo test(SQLite + filesystem) all pass.Benchmark (
examples/benchmark.rs, NVMe). Base is the published10.0.1image, which is built from the same source asdev. The differences between the two columns are within the noise between runs:🔗 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.
🤖 Generated with Claude Code