fix(db): probe WAL support and fall back to DELETE on unsupported filesystems (#990)#1177
Open
maxmilian wants to merge 1 commit into
Open
fix(db): probe WAL support and fall back to DELETE on unsupported filesystems (#990)#1177maxmilian wants to merge 1 commit into
maxmilian wants to merge 1 commit into
Conversation
…esystems (colbymchenry#990) configureConnection set journal_mode=WAL unconditionally. On filesystems where mmap(MAP_SHARED) returns EOPNOTSUPP for the WAL-index (ntfs3, WSL2 /mnt, some CIFS/NFS), PRAGMA journal_mode=WAL reports "wal" but the first write fails with SQLITE_IOERR and the connection is already corrupted, so `codegraph init` dies with "disk I/O error". Probe WAL on a throwaway database up front (walAvailable) and only enable it on the real connection when the probe survives an actual write; otherwise fall back to DELETE mode with synchronous=FULL. configureConnection now takes an explicit useWal flag computed at the two call sites.
f4708a2 to
7120da1
Compare
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.
Fixes #990.
Problem
configureConnection(src/db/index.ts) setsjournal_mode = WALunconditionally. On filesystems wheremmap(MAP_SHARED)returnsEOPNOTSUPPon the WAL-index — ntfs3, WSL2/mnt, some CIFS/NFS —PRAGMA journal_mode = WALreports"wal"but the first write fails withSQLITE_IOERR, and the connection is already corrupted (switching to another mode afterwards also fails). The user-visible symptom iscodegraph initdying withdisk I/O error.SQLite does not silently fall back here — it reports WAL as active and then fails on write.
Fix
walAvailable(dir): opens a throwaway database in the target directory, runsPRAGMA journal_mode = WALplus a realCREATE/DROPwrite (the write is what actually exercises the WAL-index mmap), and cleans up its probe files. Returnsfalseon any failure.configureConnection(db, useWal)now takes an explicit flag. WhenuseWalisfalseit falls back tojournal_mode = DELETEwithsynchronous = FULL(NORMAL is only crash-safe under WAL).initialize,open) computeuseWal = walAvailable(dir).The probe goes through the existing
createDatabaseadapter, so it honors whatever backend the connection would actually use.Testing
__tests__/wal-fallback.test.ts(all green, 72 tests pass across the touched suites):walAvailablereturnstrueon a normal writable dir and leaves no probe files behind;walAvailablereturnsfalsewhen the directory can't host a database;configureConnection(db, true)→journal_mode = wal;configureConnection(db, false)→journal_mode = deleteand writes still succeed (the point of the fallback);DatabaseConnection.initializeproduces a working WAL database on a normal fs.Honest limitation: the actual
EOPNOTSUPPpath can't be reproduced on APFS (macOS), so these tests exercise the branching + the DELETE-mode write path rather than forcing a real mmap failure. The reporter's syscall trace (mmap MAP_SHARED errno=95) plus their ntfs3/btrfs/ext4 repro substantiate the failure mode itself. Happy to add a Linux/ntfs3 CI matrix probe if that's wanted.