From b580a586dc3ebc7da22576c26a1149307e7c663a Mon Sep 17 00:00:00 2001 From: Anant Narayanan Date: Thu, 26 Jun 2008 11:15:02 -0700 Subject: [PATCH] Prevent multiple lock requests from being executed (bug 441922, r=thunder) --- services/sync/modules/async.js | 2 ++ services/sync/modules/dav.js | 13 +++++++++---- services/sync/modules/util.js | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/services/sync/modules/async.js b/services/sync/modules/async.js index fc57238dcf88..dcfbc5e3ac94 100644 --- a/services/sync/modules/async.js +++ b/services/sync/modules/async.js @@ -192,6 +192,8 @@ Generator.prototype = { this._exception = e; + } else if (e.message && e.message == 'Cannot acquire lock (internal lock)') { + this._log.warn("Exception: " + Utils.exceptionStr(e)); } else { this._log.error("Exception: " + Utils.exceptionStr(e)); this._log.debug("Stack trace:\n" + Utils.stackTrace(e)); diff --git a/services/sync/modules/dav.js b/services/sync/modules/dav.js index ee06cac87e2e..6bd01cfbc53f 100644 --- a/services/sync/modules/dav.js +++ b/services/sync/modules/dav.js @@ -252,9 +252,6 @@ DAVCollection.prototype = { }, LOCK: function DC_LOCK(path, data, onComplete) { - if (!this._lockAllowed) - throw "Cannot acquire lock (internal lock)"; - let headers = {'Content-type': 'text/xml; charset="utf-8"', 'Depth': 'infinity', 'Timeout': 'Second-600'}; @@ -364,6 +361,9 @@ DAVCollection.prototype = { let self = yield; this._log.trace("Acquiring lock"); + if (!this._lockAllowed) + throw {message: "Cannot acquire lock (internal lock)"}; + this._lockAllowed = false; if (DAVLocks['default']) { this._log.debug("Lock called, but we already hold a token"); @@ -379,8 +379,10 @@ DAVCollection.prototype = { "", self.cb); let resp = yield; - if (resp.status < 200 || resp.status >= 300) + if (resp.status < 200 || resp.status >= 300) { + this._lockAllowed = true; return; + } let tokens = Utils.xpath(resp.responseXML, '//D:locktoken/D:href'); let token = tokens.iterateNext(); @@ -393,11 +395,14 @@ DAVCollection.prototype = { if (!DAVLocks['default']) { this._log.warn("Could not acquire lock"); + this._lockAllowed = true; self.done(); return; } this._log.trace("Lock acquired"); + this._lockAllowed = true; + self.done(DAVLocks['default']); }, diff --git a/services/sync/modules/util.js b/services/sync/modules/util.js index eca9476dc1b9..52079f0f20da 100644 --- a/services/sync/modules/util.js +++ b/services/sync/modules/util.js @@ -203,7 +203,7 @@ let Utils = { }, exceptionStr: function Weave_exceptionStr(e) { - let message = e.message? e.message : e; + let message = e.message ? e.message : e; let location = ""; if (e.location)