Repository navigation
Keep the SQLite cache usable when a snapshot save fails - #450
Merged
Merged
Conversation
initialize() awaited two saves without protection: after creating a fresh
database and after applying schema migrations to an existing one. When the
full export does not fit in the WASM heap, sqlite3_js_db_export throws an
SQLite3Error ("Database serialization failed with code SQLITE_NOMEM"),
initialize() rethrows it, and the storage adapter stays failed for the whole
session; every restart repeats the same export and fails the same way.
- Both saves go through saveDuringInitialize(), which marks the database
dirty first (the migrator writes through the raw handle, so nothing else
would) and logs instead of rethrowing. Auto-save and close() retry.
- isAllocationFailure() recognises the SQLITE_NOMEM export failure as well
as the RangeError of a JS-side copy, so the existing exponential back-off
also applies to it instead of re-exporting on every tick. resultCode is
the generic SQLITE_ERROR for this throw, so the message is what carries it.
Tests cover both init paths, the retry after a failed init save, the back-off
after SQLITE_NOMEM at init and at runtime, and the adapter staying query-ready.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 082766a)
Route recovered cache snapshots through startup save handling and let manual rebuild discard the old cache after its active blob write settles. Finish hydration when replay succeeds and only the final snapshot save fails.
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
SQLITE_NOMEMbackoff from the work in Cache: survive a failed save in initialize, export without a second in-heap copy, never export mid-transaction #449.Fixes #448.
Verification