summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2014-01-07 11:05:39 -0200
committerdrebs <drebs@leap.se>2014-01-07 11:05:39 -0200
commit82628d8284c5c11452da75a6604f2f68b8dd8520 (patch)
tree2e7280c065301306611fd60d614111c19e43acaa
parentf98f66549d6762bbfc072ef6afe0057798a4da27 (diff)
Use temp dir for server side locks (#4918).
-rw-r--r--common/src/leap/soledad/common/errors.py11
-rw-r--r--server/changes/feature_4918_use-temporary-directory-for-server-side-locks1
-rw-r--r--server/src/leap/soledad/server/__init__.py10
3 files changed, 19 insertions, 3 deletions
diff --git a/common/src/leap/soledad/common/errors.py b/common/src/leap/soledad/common/errors.py
index 62de19f8..c41e0b0f 100644
--- a/common/src/leap/soledad/common/errors.py
+++ b/common/src/leap/soledad/common/errors.py
@@ -67,10 +67,19 @@ class LockTimedOutError(errors.U1DBError):
status = 408
+class CouldNotObtainLockError(errors.U1DBError):
+ """
+ Exception raised when timing out while trying to lock the shared database.
+ """
+
+ wire_description = "error obtaining lock"
+ status = 500
+
+
# update u1db "wire description to status" and "wire description to exception"
# maps.
for e in [InvalidTokenError, NotLockedError, AlreadyLockedError,
- LockTimedOutError]:
+ LockTimedOutError, CouldNotObtainLockError]:
http_errors.wire_description_to_status.update({
e.wire_description: e.status})
errors.wire_description_to_exc.update({
diff --git a/server/changes/feature_4918_use-temporary-directory-for-server-side-locks b/server/changes/feature_4918_use-temporary-directory-for-server-side-locks
new file mode 100644
index 00000000..d8c5ba8e
--- /dev/null
+++ b/server/changes/feature_4918_use-temporary-directory-for-server-side-locks
@@ -0,0 +1 @@
+ o Use a temporary directory for server side locks (#4918).
diff --git a/server/src/leap/soledad/server/__init__.py b/server/src/leap/soledad/server/__init__.py
index 00d3c8c1..4380966c 100644
--- a/server/src/leap/soledad/server/__init__.py
+++ b/server/src/leap/soledad/server/__init__.py
@@ -90,6 +90,7 @@ import configparser
import time
import hashlib
import os
+import tempfile
from u1db.remote import http_app
@@ -122,6 +123,7 @@ from leap.soledad.common.errors import (
NotLockedError,
AlreadyLockedError,
LockTimedOutError,
+ CouldNotObtainLockError,
)
@@ -201,7 +203,9 @@ class LockResource(object):
self._shared_db = state.open_database(SoledadApp.SHARED_DB_NAME)
self._lock_doc_id = '%s%s' % (SHARED_DB_LOCK_DOC_ID_PREFIX, uuid)
self._lock = FilesystemLock(
- hashlib.sha512(self._lock_doc_id).hexdigest())
+ os.path.join(
+ tempfile.gettmpdir(),
+ hashlib.sha512(self._lock_doc_id).hexdigest()))
self._state = state
self._responder = responder
@@ -328,8 +332,10 @@ class LockResource(object):
while tries > 0:
try:
return self._lock.lock()
- except Exception as e:
+ except OSError as e:
tries -= 1
+ if tries == 0:
+ raise CouldNotObtainLockError(e.message)
time.sleep(self.FILESYSTEM_LOCK_SLEEP_SECONDS)
return False