fix(export): add time/size guards to dumpDatabaseRoute for large DBs#232
Open
CuboYe wants to merge 1 commit into
Open
fix(export): add time/size guards to dumpDatabaseRoute for large DBs#232CuboYe wants to merge 1 commit into
CuboYe wants to merge 1 commit into
Conversation
- Pre-export estimate via pragma_page_count — fail fast with 413 if >100 MB - Per-table runtime budget (10s) + row count guard (500k) to prevent unbounded INSERT loops - Global 20s time budget checked between tables - Clear error messages pointing to per-table /export/csv/:tableName fallback Fixes outerbase#59
Author
|
Checking in — any questions on the approach? Happy to adjust the time budget thresholds or add R2 streaming if preferred. |
Author
|
Friendly bump — PR is ready for review. |
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.
/claim #59
Problem
/export/dumploads the entire database into memory before returning a file. For large databases (>1 GB, approaching Durable Object limits), this causes OOM or hangs past the 30s request timeout with no error message or partial result.Fix
src/export/dump.ts— three layers of defence:Pre-export size estimate — runs
pragma_page_count+ schema size query before loading any row data. Fails fast with 413 if estimated dump >100 MB, with a clear message pointing to per-table fallbacks.Per-table runtime budget (10s) — checked between rows inside the INSERT loop for each table. Catches tables with millions of rows mid-export, before they consume all memory.
Global time budget (20s) — checked between tables. Stops export cleanly after N tables and tells the caller exactly which table caused the overflow and how many remain.
Error messages are actionable: they name the failing table, the row count if hit, and direct users to
/export/csv/:tableName//export/json/:tableNameas a workaround.What didn't change
Testing
pragma_page_countquery works in the existing test harnessDate.now()mock via Vitest