don't fail on invalid server deltas which don't apply to the local snapshot; wipe the local snapshot instead
don't fail on invalid server deltas which don't apply to the local snapshot; wipe the local snapshot instead
--- a/services/sync/modules/engines.js
+++ b/services/sync/modules/engines.js
@@ -566,19 +566,27 @@ Engine.prototype = {
allDeltas = this._json.decode(data);
deltas = [];
} else { // this._snapshot.version > status.maxVersion
this._log.error("Server snapshot is older than local snapshot");
break;
}
- for (var i = 0; i < deltas.length; i++) {
- snap.applyCommands.async(snap, self.cb, deltas[i]);
- yield;
+ try {
+ for (var i = 0; i < deltas.length; i++) {
+ snap.applyCommands.async(snap, self.cb, deltas[i]);
+ yield;
+ }
+ } catch (e) {
+ this._log.error("Error applying remote deltas to saved snapshot");
+ this._log.error("Clearing local snapshot; next sync will merge");
+ this._log.debug("Exception: " + Utils.exceptionStr(e));
+ this._log.trace("Stack:\n" + Utils.stackTrace(e));
+ this._snapshot.wipe();
}
ret.status = 0;
ret.formatVersion = status.formatVersion;
ret.maxVersion = status.maxVersion;
ret.snapVersion = status.snapVersion;
ret.snapEncryption = status.snapEncryption;
ret.deltasEncryption = status.deltasEncryption;