fix(core): detect NFS and use local database path to prevent corruption#15131
Open
jerry-xu0514 wants to merge 2 commits intoanomalyco:devfrom
Open
fix(core): detect NFS and use local database path to prevent corruption#15131jerry-xu0514 wants to merge 2 commits intoanomalyco:devfrom
jerry-xu0514 wants to merge 2 commits intoanomalyco:devfrom
Conversation
SQLite's WAL mode uses shared memory mappings (mmap) via the -shm file, which are incoherent across NFS clients. This causes database corruption when multiple opencode sessions write concurrently on NFS-mounted home directories. Detect NFS via statfs magic number (0x6969) and fall back to a local tmpdir path. Also add integrity checks on startup with auto-recreation to make corruption self-healing instead of a hard crash. Fixes anomalyco#14970
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
The previous approach tried to move the database to /tmp on NFS, but: - Was never deployed (installed binary was still the old one) - Would lose data on reboot - Used integrity_check which hangs on large corrupt databases New approach: - Detect NFS via statfsSync and use DELETE journal mode (no mmap/-shm) - Use quick_check instead of integrity_check (fast, won't hang) - Set busy_timeout before journal mode change (NFS stale locks) - Wrap journal mode change in try/catch (graceful fallback) - Keep corruption recovery as defense in depth
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.
Issue for this PR
Closes #14970
Type of change
What does this PR do?
SQLite's WAL mode uses shared memory mappings (mmap) via the
-shmfile. On NFS, these mappings are incoherent across clients and POSIXfcntl()locks are unreliable. Multiple opencode sessions writing to the same WAL-mode database on NFS corrupts the database almost immediately.This PR:
statfsSync().type === 0x6969and redirects the database to/tmp/opencode-{uid}/on a local filesystemwal_checkpointin try/catch to handle stale WAL stateHow did you verify your code works?
Tested on a live NFSv3 environment (
local_lock=none) where the bug reproduces consistently:statfsSyncreturns0x6969for the NFS mount/tmp/opencode-{uid}/opencode.dbinstead of the NFS pathScreenshots / recordings
N/A — no UI changes.
Checklist