MCPcopy
hub / github.com/codedogQBY/ReadAny / withDatabaseLockRetry

Function withDatabaseLockRetry

packages/core/src/sync/simple-sync.ts:141–162  ·  view source on GitHub ↗
(operation: () => Promise<T>, label: string)

Source from the content-addressed store, hash-verified

139}
140
141async function withDatabaseLockRetry<T>(operation: () => Promise<T>, label: string): Promise<T> {
142 let lastError: unknown;
143
144 for (let attempt = 1; attempt <= DB_LOCK_MAX_RETRIES; attempt++) {
145 try {
146 return await operation();
147 } catch (error) {
148 lastError = error;
149 if (!isDatabaseLockedError(error) || attempt === DB_LOCK_MAX_RETRIES) {
150 throw error;
151 }
152
153 const delay = DB_LOCK_RETRY_DELAY_MS * attempt;
154 console.warn(
155 `[SimpleSync] ${label} hit a locked database, retrying (${attempt}/${DB_LOCK_MAX_RETRIES}) in ${delay}ms...`,
156 );
157 await sleep(delay);
158 }
159 }
160
161 throw lastError instanceof Error ? lastError : new Error(String(lastError));
162}
163
164export interface TableChangeset {
165 records: Record<string, unknown>[];

Callers 1

applyChangesFunction · 0.85

Calls 2

isDatabaseLockedErrorFunction · 0.85
sleepFunction · 0.70

Tested by

no test coverage detected