Skip to content

Fix iOS SQLite recreate by cleaning up companion journal/WAL files#1484

Open
bmehta001 wants to merge 1 commit into
microsoft:mainfrom
bmehta001:bhamehta/ios-offline-recreate-fix
Open

Fix iOS SQLite recreate by cleaning up companion journal/WAL files#1484
bmehta001 wants to merge 1 commit into
microsoft:mainfrom
bmehta001:bhamehta/ios-offline-recreate-fix

Conversation

@bmehta001

Copy link
Copy Markdown
Contributor

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::initialize the deletePrevious path deleted only 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

Delete the main DB file plus its -journal / -wal / -shm companions in the deletePrevious path. 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

  • Built UnitTests (Release x64, v145) and ran the full OfflineStorageTests_SQLite suite on Windows: 43/43 pass — no desktop regression.
  • iOS behavior is validated by this PR's CI (no Apple toolchain available locally). Draft until the macOS/iOS jobs confirm the fix.

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>
@bmehta001 bmehta001 marked this pull request as ready for review June 13, 2026 00:42
@bmehta001 bmehta001 requested a review from a team as a code owner June 13, 2026 00:42
@bmehta001 bmehta001 requested a review from Copilot June 13, 2026 00:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 -shm companions via the SQLite VFS.
  • Treat failure to delete the main DB file as fatal, while non-NOENT failures 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants