Reinitialize sync engine after three failed trials (#283)

* After extended suspend, or bad connection, the connection to OD might
go stale - thus no network connection to Microsoft OneDrive Service, skipping sync
and this continues ad infinitum. Change the last action to re-initialize the sync engine.
This commit is contained in:
Norbert Preining 2018-12-13 05:08:18 +09:00 committed by abraunegg
parent 6a62406db7
commit 91aaf91aa6
2 changed files with 23 additions and 11 deletions

View file

@ -398,17 +398,21 @@ int main(string[] args)
onedrive.http.shutdown();
return EXIT_FAILURE;
}
performSync(sync, singleDirectory, downloadOnly, localFirst, uploadOnly);
if (!downloadOnly) {
// discard all events that may have been generated by the sync
m.update(false);
try {
performSync(sync, singleDirectory, downloadOnly, localFirst, uploadOnly);
if (!downloadOnly) {
// discard all events that may have been generated by the sync
m.update(false);
}
} catch (CurlException e) {
// we already tried three times in the performSync routine
// if we still have problems, then the sync handle might have
// gone stale and we need to re-initialize the sync engine
log.log("Pesistent connection errors, reinitializing connection");
sync.reset();
}
} catch (CurlException e) {
// TODO better check of type of exception from Curl
// could be either timeout of operation of connection error
// No network connection to OneDrive Service
// Don't overload notifications
log.log("No network connection to Microsoft OneDrive Service, skipping sync");
log.log("Cannot initialize connection to OneDrive");
}
// performSync complete, set lastCheckTime to current time
lastCheckTime = MonoTime.currTime();
@ -514,8 +518,11 @@ void performSync(SyncEngine sync, string singleDirectory, bool downloadOnly, boo
}
count = -1;
} catch (Exception e) {
if (++count == 3) throw e;
else log.log("Retrial sync count: ", count, ": ", e.msg);
if (++count == 3) {
log.log("Giving up on sync after three attempts: ", e.msg);
throw e;
} else
log.log("Retry sync count: ", count, ": ", e.msg);
}
} while (count != -1);
}

View file

@ -180,6 +180,11 @@ final class SyncEngine
session = UploadSession(onedrive, cfg.uploadStateFilePath);
}
void reset()
{
initDone=false;
}
void init()
{
// Set accountType, defaultDriveId, defaultRootId & remainingFreeSpace once and reuse where possible