Debugging sync getting stuck

This commit is contained in:
Zef Hemel
2023-08-08 17:19:43 +02:00
parent 2f1f266482
commit e805a1ced0
+8 -3
View File
@@ -84,6 +84,7 @@ export class SyncService {
// It's been too long since the last activity, let's consider this one crashed and // It's been too long since the last activity, let's consider this one crashed and
// reset the sync start state // reset the sync start state
await this.kvStore.del(syncStartTimeKey); await this.kvStore.del(syncStartTimeKey);
console.info("Sync crashed, resetting");
return false; return false;
} }
return true; return true;
@@ -138,10 +139,14 @@ export class SyncService {
} }
// Await a moment when the sync is no longer running // Await a moment when the sync is no longer running
async noOngoingSync(): Promise<void> { async noOngoingSync(timeout: number): Promise<void> {
// Not completely safe, could have race condition on setting the syncStartTimeKey // Not completely safe, could have race condition on setting the syncStartTimeKey
const startTime = Date.now();
while (await this.isSyncing()) { while (await this.isSyncing()) {
await sleep(250); await sleep(250);
if (Date.now() - startTime > timeout) {
throw new Error("Timeout waiting for sync to finish");
}
} }
} }
@@ -153,7 +158,7 @@ export class SyncService {
return; return;
} }
this.filesScheduledForSync.add(path); this.filesScheduledForSync.add(path);
await this.noOngoingSync(); await this.noOngoingSync(5000);
await this.syncFile(path); await this.syncFile(path);
this.filesScheduledForSync.delete(path); this.filesScheduledForSync.delete(path);
} }
@@ -181,7 +186,7 @@ export class SyncService {
async syncSpace(): Promise<number> { async syncSpace(): Promise<number> {
if (await this.isSyncing()) { if (await this.isSyncing()) {
console.log("Already syncing"); console.log("Aborting space sync: already syncing");
return 0; return 0;
} }
await this.registerSyncStart(true); await this.registerSyncStart(true);