fix: detect IDB backing store corruption and heal or degrade gracefully#780
Draft
leshniak wants to merge 2 commits intoExpensify:mainfrom
Draft
fix: detect IDB backing store corruption and heal or degrade gracefully#780leshniak wants to merge 2 commits intoExpensify:mainfrom
leshniak wants to merge 2 commits intoExpensify:mainfrom
Conversation
Three bugs prevented Onyx from handling Chromium IDB corruption (884K errors/month, 26.3% of all storage errors): 1. createStore cached rejected promises — once indexedDB.open() failed, every subsequent operation returned the same rejection forever, creating infinite error loops on idle tabs. 2. createStore only retried InvalidStateError — the backing store UnknownError fell through unhandled with no heal attempt. 3. tryOrDegradePerformance used try/catch which only catches sync throws, but IDB errors are async rejections that bypassed it entirely, so degradePerformance was never called. Fix: clear cached rejected dbp on failure, detect backing store corruption and attempt deleteDatabase heal in createStore, rewrite tryOrDegradePerformance to catch async rejections as last-resort fallback to MemoryOnlyProvider. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Details
Fixes three bugs that prevent Onyx from handling Chromium IDB corruption (
UnknownError: Internal error opening backing store for indexedDB.open.— 884K errors/month, 26.3% of all storage errors, investigation).Bug 1 — Cached rejected promise:
createStore'sgetDB()caches thedbppromise. IfindexedDB.open()rejects,dbpis a rejected promise that's truthy, so every subsequent call returns the same rejection forever. This creates infinite error loops on idle tabs (observed in Fullstory: errors every 30–60s with zero user interaction).Bug 2 — No backing store handling:
createStore's catch handler only retriesInvalidStateError. TheUnknownErrorbacking store corruption falls through tothrow errorwith no heal attempt.Bug 3 — Async escape:
tryOrDegradePerformancewrapsfn()in a synctry/catch, but IDB operations return promises. The async rejection passes throughresolve(fn())and never hits the catch block, sodegradePerformanceis never called.Changes:
createStore.ts: Cleardbpon rejection so next operation retries fresh. Detect backing store corruption → attemptindexedDB.deleteDatabase()heal → retry once. If heal fails, error propagates.storage/index.ts: RewritetryOrDegradePerformancefromnew Promise+try/catchto.then().catch()— catches both sync throws and async rejections. Falls back toMemoryOnlyProvideras last resort.Related Issues
Expensify/App#87862
Automated Tests
4 new tests in
tests/unit/storage/StorageCorruptionTest.ts:tryOrDegradePerformancecatches async IDB rejections and degrades toMemoryOnlyProviderindexedDB.openmock, verifiesdeleteDatabase('OnyxDB')is called, operation succeeds after healdeleteDatabasealso fails, verifies fallback toMemoryOnlyProviderQuotaExceededErrordoes NOT trigger corruption healing or degradationAll 439 tests pass.
Manual Tests
npm run typecheckpassesnpm run lintpassesnpm testpasses (439/439)OnyxDBLevelDB files) and verify heal or degrade behaviorAuthor Checklist
### Related Issuessection aboveTestssectiontoggleReportand notonIconClick)myBool && <MyComponent />.STYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
N/A — library-level change, no UI
Android: mWeb Chrome
N/A — library-level change, no UI
iOS: Native
N/A — library-level change, no UI
iOS: mWeb Safari
N/A — library-level change, no UI
MacOS: Chrome / Safari
N/A — library-level change, no UI