Correctly cancel any sync triggers after starting a sync with a shared function that removes timers and idle observers.
Correctly cancel any sync triggers after starting a sync with a shared function that removes timers and idle observers.
--- a/services/sync/modules/service.js
+++ b/services/sync/modules/service.js
@@ -981,32 +981,41 @@ WeaveSvc.prototype = {
reason = kSyncNotScheduled;
else if (this.status.minimumNextSync > Date.now())
reason = kSyncBackoffNotMet;
return reason;
},
/**
+ * Remove any timers/observers that might trigger a sync
+ */
+ _clearSyncTriggers: function _clearSyncTriggers() {
+ // Clear out any scheduled syncs
+ if (this._syncTimer) {
+ this._syncTimer.cancel();
+ this._syncTimer = null;
+ }
+
+ // Clear out a sync that's just waiting for idle if we happen to have one
+ try {
+ Svc.Idle.removeIdleObserver(this, IDLE_TIME);
+ }
+ catch(ex) {}
+ },
+
+ /**
* Check if we should be syncing and schedule the next sync, if it's not scheduled
*/
_checkSyncStatus: function WeaveSvc__checkSyncStatus() {
// Should we be syncing now, if not, cancel any sync timers and return
// if we're in backoff, we'll schedule the next sync
let reason = this._checkSync();
if (reason && reason != kSyncBackoffNotMet) {
- if (this._syncTimer) {
- this._syncTimer.cancel();
- this._syncTimer = null;
- }
-
- try {
- Svc.Idle.removeIdleObserver(this, IDLE_TIME);
- } catch(e) {} // this throws if there isn't an observer, but that's fine
-
+ this._clearSyncTriggers();
this.status.service = STATUS_DISABLED;
return;
}
// otherwise, schedule the sync
this._scheduleNextSync();
},
@@ -1088,20 +1097,18 @@ WeaveSvc.prototype = {
let reason = this._checkSync();
if (reason && (useThresh || reason != kSyncNotScheduled)) {
// this is a purposeful abort rather than a failure, so don't set
// any status bits
reason = "Can't sync: " + reason;
throw reason;
}
- if (this._autoConnectTimer) {
- this._autoConnectTimer.cancel();
- this._autoConnectTimer = null;
- }
+ // Clear out any potentially pending syncs now that we're syncing
+ this._clearSyncTriggers();
if (!(this._remoteSetup()))
throw "aborting sync, remote setup failed";
// Figure out what the last modified time is for each collection
let info = new Resource(this.infoURL).get();
if (!info.success)
throw "aborting sync, failed to get collections";