fix: stream SQL database dumps#206
Conversation
digzrow-coder
left a comment
There was a problem hiding this comment.
I think this still has the memory failure mode the issue is trying to remove. The export producer runs inside the stream's start() callback and loops through every table/page, calling controller.enqueue(...) without checking/awaiting backpressure. In Web Streams, start() is kicked off when the stream is created; it is not tied to downstream reads. If the client is slow, or if the runtime cannot flush the response as fast as SQLite pages are read, this can queue arbitrarily many encoded chunks in the isolate. A 10GB dump can therefore still grow toward dump-size memory, just in the stream queue instead of in one string/blob.
A safer shape is to make the stream pull-driven: do one schema/page of work from pull(controller) (or use a TransformStream/writer path that awaits backpressure) and only fetch the next SQLite page after the previous queued chunk has been consumed. That keeps memory bounded by a small number of pages instead of the full dump size.
|
Thanks for the careful review. I pushed The dump stream is now pull-driven instead of doing the table/page loop inside I also added a regression test that reads only through the schema chunk and verifies the next Validation re-run: npx --yes vitest run src/export/dump.test.ts
npx --yes prettier --check src/export/dump.ts src/export/dump.test.ts
git diff --check |

/claim #59
Summary
This is a focused streaming slice for the large database dump issue.
Instead of building the entire SQL dump in a single in-memory string/blob,
/export/dumpnow returns aReadableStreamand writes the dump incrementally:LIMIT ? OFFSET ?pagesINSERTstatements as it is producedNULL, booleans, bigint, and binary valuesThis does not attempt to solve the full async/R2 continuation path in one PR. It removes the immediate O(database dump size) string allocation while keeping the existing endpoint behavior intact, so it can compose with later R2/alarm work.
Validation
./node_modules/.bin/prettier --check src/export/dump.ts src/export/dump.test.ts./node_modules/.bin/vitest run src/export/dump.test.ts(6 tests)git diff --checkThe repo-wide
./node_modules/.bin/tsc --noEmitis still blocked by pre-existing type errors outside this PR (src/do.ts,src/operation.ts, existing tests). The focused dump tests and formatting checks pass.