Skip to content

Classify SQLite disk-pressure errors and stop retrying them - #816

Draft
elirangoshen wants to merge 2 commits into
Expensify:mainfrom
callstack-internal:eliran/87869-classify-disk-pressure
Draft

Classify SQLite disk-pressure errors and stop retrying them#816
elirangoshen wants to merge 2 commits into
Expensify:mainfrom
callstack-internal:eliran/87869-classify-disk-pressure

Conversation

@elirangoshen

@elirangoshen elirangoshen commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Details

Fixes the app-side symptom of Expensify/App#87869 — iOS bursts of NitroSQLiteError: [NativeNitroSQLiteException][SqlExecutionError] disk I/O error (Sentry APP-19Q).

Root cause (reproduced locally on an iOS simulator): when the device disk is full at database (re)open, SQLite fails to ftruncate the OnyxDB-shm WAL-index file to 32KB (errno 28 ENOSPCSQLITE_IOERR_SHMSIZE), after which every read and write returns disk I/O error until space frees — then it recovers on its own. Two related shapes of the same condition:

  • unable to open database file (SQLITE_CANTOPEN) — the -shm file cannot be created at all
  • cannot rollback - no transaction is active — a batch-write failure whose original error was masked by the ROLLBACK itself failing on the same full disk

Before this PR these errors fell in the UNKNOWN storage error class: 5 blind retries per operation (futile — the disk is still full) plus a per-operation alert, amplifying the very log storm being reported (~70x amplification seen in prod logs).

This PR:

  • Adds a new DISK_PRESSURE storage error class (lib/storage/errors.ts)
  • classifySQLiteError routes the three messages above to it (lib/storage/providers/classifySQLiteError.ts)
  • retryOperation drops the write (the in-memory cache stays authoritative), skips retries and eviction (neither can free OS-level disk space), and logs a single throttled alert (60s window) plus one storage quota snapshot per burst (lib/OnyxUtils.ts)
  • On native, the quota snapshot includes getFreeDiskStorage() bytes, giving prod telemetry the free-disk data to confirm disk pressure as the root cause

Related Issues

Expensify/App#87869

Linked E/App PR

TBD — companion Expensify/App pin PR not opened yet

Automated Tests

Added to tests/unit/onyxUtilsTest.ts:

  • it.each over the three disk-pressure error strings (disk I/O error, unable to open database file, cannot rollback - no transaction is active) asserting the operation is not retried
  • A burst test asserting exactly one throttled alert + one storage quota snapshot across a burst of failing operations, and no "retries exhausted" alert

Full unit suite passes (569 tests).

Manual Tests

Regression smoke (no user-facing change in this PR — it only alters error classification/logging):

  1. Sign in and use the app normally: open a report, create an expense, send a message.
  2. Go offline, create an expense, kill and relaunch the app — verify the offline change is still there and syncs when back online.
  3. Verify no crashes or console errors during normal usage.

Author Checklist

  • I linked the correct issue in the ### Related Issues section above
  • I linked the corresponding Expensify/App PR in the ### Linked E/App PR section above, and verified this change against it (E/App CI passed and manual testing completed)
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • If we are not using the full Onyx data that we loaded, I've added the proper selector in order to ensure the component only re-renders when the data it is using changes
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

Full device disk surfaces as "disk I/O error" (SQLITE_IOERR, shm sizing on
open), "unable to open database file" (SQLITE_CANTOPEN), or "cannot rollback -
no transaction is active" (failed ROLLBACK masking the original write error).
All were UNKNOWN: 5 futile retries per operation plus per-operation alerts.

New DISK_PRESSURE class drops the write (cache stays authoritative), skips
retries and eviction (neither frees OS-level space), and logs one throttled
alert + storage quota snapshot per burst — the snapshot carries free-disk
bytes so telemetry can confirm disk pressure as the root cause.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@sosek108 sosek108 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.

Got some comments,

// Full-disk failures around the database files: SQLITE_IOERR (cannot size the -shm file on reopen,
// fails reads too), SQLITE_CANTOPEN (cannot create it), and a failed ROLLBACK masking the original
// write error. None can succeed until the OS frees space.
if (message.includes('disk i/o error') || message.includes('unable to open database file') || message.includes('cannot rollback - no transaction is active')) {

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.

Are you sure that cannot rollback - no transaction is active is 100% related to disk pressure?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

its not 100 percent so I edit the comments to reflect it better

Comment thread lib/storage/errors.ts
/** Filesystem-level failure around the database files (device disk full, or the files cannot be
* created/read). Owner: operation layer — skip retries and eviction (neither can free OS-level
* space) and log one throttled alert + quota snapshot per burst. */
DISK_PRESSURE: 'diskPressure',

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.

How this is different from CAPACITY?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

their both related to disk full but CAPACITY usually means the onyx keys is full and evict some keys can fix while in DISK_PRESSURE its when os file system is full so there is no way to fix it unless free space.

Comment thread lib/OnyxUtils.ts
Comment on lines +825 to +833
if (errorClass === StorageErrorClass.DISK_PRESSURE) {
const now = Date.now();
if (now - lastDiskPressureLogTime < DISK_PRESSURE_LOG_INTERVAL_MS) {
return Promise.resolve();
}
lastDiskPressureLogTime = now;
Logger.logAlert(`Disk-pressure storage error; skipping retries. provider: ${Storage.getStorageProvider().name}. message: ${error?.message}. onyxMethod: ${onyxMethod.name}.`);
return reportStorageQuota(error);
}

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.

The goal is not to send so many logs to VL, right?

This is why we introduced CircuitBreaker.

@elirangoshen elirangoshen Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

They solve different problems. The circuit breaker stops the evict → retry loop for CAPACITY errors. DISK_PRESSURE has no loop to stop — we never retry or evict, the write is just dropped. The only thing left to limit is log volume, and the 60s throttle does that. Putting it through the breaker wouldn't work anyway: the breaker's recovery probe is an eviction, which can't fix a full disk.

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