Fix iOS SQLite recreate by cleaning up companion journal/WAL files#1484
Open
bmehta001 wants to merge 1 commit into
Open
Fix iOS SQLite recreate by cleaning up companion journal/WAL files#1484bmehta001 wants to merge 1 commit into
bmehta001 wants to merge 1 commit into
Conversation
OfflineStorageTests_SQLite.InitializeDeletesFileAndCreatesNewIfFailed fails only on iOS: after a corrupt DB is detected, recreate() opens with deletePrevious=true, but the open then fails and OnStorageOpened reports "SQLite/None" instead of the expected "SQLite/Clean". Root cause hypothesis: deletePrevious only removed the main database file via the SQLite VFS xDelete. A stale -journal/-wal/-shm companion left behind by the failed first open can prevent the freshly created database from opening cleanly. This is benign on Windows/Linux (where the test passes) but trips the iOS VFS. Fix: in SQLiteWrapper::initialize's deletePrevious path, delete the main DB file plus its -journal/-wal/-shm companions. Only a failure to delete the main file is fatal; a leftover companion that cannot be removed no longer aborts the recreate, since the subsequent open may still succeed. No desktop regression: built UnitTests (Release x64, v145) and ran the full OfflineStorageTests_SQLite suite -- 43/43 pass on Windows. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses an iOS-only failure in the SQLite offline storage “recreate” path by ensuring that when a corrupted DB is deleted, SQLite’s companion files are also removed to prevent subsequent open failures under the iOS VFS.
Changes:
- Update
SqliteDB::initialize(..., deletePrevious=true)to delete the main DB file as well as-journal,-wal, and-shmcompanions via the SQLite VFS. - Treat failure to delete the main DB file as fatal, while non-
NOENTfailures deleting companion files only log a warning and allow the recreate to proceed.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Problem
OfflineStorageTests_SQLite.InitializeDeletesFileAndCreatesNewIfFailed fails only on iOS CI. The test writes garbage into the DB file, then expects Initialize() to detect corruption, call
ecreate(1), and report OnStorageFailed("1") + OnStorageOpened("SQLite/Clean"). On iOS the recreate open fails and OnStorageOpened instead reports "SQLite/None".
Root cause (hypothesis)
In
SQLiteWrapper::initializethedeletePreviouspath deleted only the main database file via the SQLite VFSxDelete. A stale-journal/-wal/-shmcompanion left behind by the failed first open can prevent the freshly created database from opening cleanly. This is benign on Windows/Linux (where the test passes) but trips the iOS VFS.Fix
Delete the main DB file plus its
-journal/-wal/-shmcompanions in thedeletePreviouspath. Only failure to delete the main file is treated as fatal; a leftover companion that cannot be removed no longer aborts the recreate, since the subsequent open may still succeed.SQLITE_IOERR_DELETE_NOENT(file already absent) remains expected/non-fatal.Validation
UnitTests(Release x64, v145) and ran the fullOfflineStorageTests_SQLitesuite on Windows: 43/43 pass — no desktop regression.