Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions lib/OnyxUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,32 @@ function evictStorageAndRetry<TMethod extends typeof Onyx.set | typeof Onyx.mult
// Find the first key that we can remove that has no subscribers in our blocklist
const keyForRemoval = cache.getKeyForEviction();
if (!keyForRemoval) {
const allKeys = Array.from(cache.getAllKeys());
const evictionBlocklist = cache.getEvictionBlocklist();

let evictableCount = 0;
let blockedCount = 0;
const evictableKeys: string[] = [];
allKeys.forEach((key) => {
if (!cache.isEvictableKey(key)) {
return;
}

evictableCount++;
evictableKeys.push(key);
if (evictionBlocklist[key]) {
blockedCount++;
}
});

Logger.logHmmm(
`Out of storage eviction failure debug:\n` +
`Total keys in storage: ${allKeys.length}\n` +
`Evictable keys found: ${evictableCount}\n` +
`Evictable keys blocked: ${blockedCount}\n` +
`Keys in eviction blocklist: ${Object.keys(evictionBlocklist).length}`,
);

// If we have no acceptable keys to remove then we are possibly trying to save mission critical data. If this is the case,
// then we should stop retrying as there is not much the user can do to fix this. Instead of getting them stuck in an infinite loop we
// will allow this write to be skipped.
Expand Down
14 changes: 13 additions & 1 deletion lib/storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,19 @@ function tryOrDegradePerformance<T>(fn: () => Promise<T> | T, waitForInitializat

promise.then(() => {
try {
resolve(fn());
const result = fn();

// Handle promise rejections for async operations
if (result instanceof Promise) {
result
.then((value) => resolve(value))
.catch((promiseError) => {
// Pass through all async errors to higher-level error handling
reject(promiseError);
});
} else {
resolve(result);
}
} catch (error) {
// Test for known critical errors that the storage provider throws, e.g. when storage is full
if (error instanceof Error) {
Expand Down