Fix LMDB errors and add recovery mechanisms #373
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.
1. MDB_BAD_RSLOT (Fork Detection Issues)
Error Message:
Cause:
LMDB uses memory-mapped files with process-specific reader lock slots. When a process forks (common in VS Code's extension host), the child process inherits the parent's LMDB environment but the reader lock table still references the parent's PID. Any read operation in the child triggers this error.
2. MDB_CORRUPTED / MDB_PAGE_NOTFOUND
Error Messages:
Cause:
These errors indicate the B+ tree structure is inconsistent - either a page pointer references the wrong page type, or a referenced page doesn't exist.
3. Closed Database Errors
Error Message:
Cause:
Operations attempted on an LMDB environment that was closed (either explicitly or due to error recovery). The
renewReadTxnfunction tries to reuse a transaction from an invalidated environment.4. MDB_BAD_TXN
Error Message:
Cause:
Transaction state corruption, often from:
Implemented Fixes
Fix 1: Proactive Fork Detection
openPid)Addresses: MDB_BAD_RSLOT errors (2,856 occurrences)
Fix 2: Reactive Error Recovery
Fix 3: Environment Recreation
Fix 4: Store Handle Updates
Fix 5: Operation Wrapping
validateDatabase()first (fork detection)onError()triggers recovery