Fix/wal growth and goroutine leak#1204
Conversation
SQLite's default PASSIVE auto-checkpoint fails silently when readers are continuously active, causing the WAL file to grow without bound (observed up to 32GB in production). This adds a background goroutine that runs PRAGMA wal_checkpoint(TRUNCATE) every minute. TRUNCATE mode: - Waits for writers to finish - Moves all WAL content to the main database - Resets and truncates the WAL file to zero bytes Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
When an HTTP client disconnects mid-watch, the forwarder goroutines would block forever on channel send operations because they had no way to detect context cancellation. Add select on ctx.Done() to both forwarder loops: - pkg/stores/sqlproxy/proxy_store.go: WatchByPartitions - pkg/stores/sqlpartition/store.go: Watch This allows goroutines to exit cleanly when the request context is cancelled, preventing the observed goroutine leak (~30 leaked goroutines per 6 minutes). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
fe00375 to
f356a29
Compare
Investigation Summary & Test ResultsThis PR addresses two issues observed in steve v0.7.43 (Rancher 2.13.5):
Root Cause AnalysisWAL Growth (Reader Starvation)SQLite's default auto-checkpoint is PASSIVE — it never waits for readers, and critically, it cannot reset the WAL write pointer when any reader holds a snapshot. In steve, concurrent
This is documented behavior: sqlite.org/wal.html:
Goroutine Leak
What This PR DoesCommit 1: Background WAL Checkpoint
Commit 2: Goroutine Leak Fix
Integration Test ResultsWe created a stress test suite (branch Test configuration: 10 watchers + 5 writers + 50 concurrent listers, running for 20 minutes. WITHOUT fix:
WITH fix (same workload):
The fix eliminates unbounded WAL growth while maintaining the same throughput. Connection-close test (goroutine leak):Tested 30 clients abandoning mid-stream + 10 watch disconnects. Goroutines returned to baseline (35) after all contexts cancelled — no goroutine leak with the fix applied. Code Locations
Related Branches (on gehrkefc/steve fork)
|
No description provided.