diff options
author | drebs <drebs@riseup.net> | 2017-10-10 07:43:19 -0300 |
---|---|---|
committer | drebs <drebs@riseup.net> | 2017-10-10 07:52:28 -0300 |
commit | 850a0e32f996cdcc6724e3900a40325aae719828 (patch) | |
tree | 030b2c189b972c1c9de83bb70c00e1d5fdb92d7e /src/leap/soledad/server | |
parent | a744f9d6de8f0e2fd9be95a2be6af44f9874d238 (diff) |
[bug] handle put errors in the incoming blobs api
An errback was missing in the PUT renderer method of the incoming API.
Because of that, requests to that endpoint were not being correctly
finished in case of errors when writing blobs. That was causing delivery
requests to hang until timeout.
Closes: #8977
Diffstat (limited to 'src/leap/soledad/server')
-rw-r--r-- | src/leap/soledad/server/_incoming.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/leap/soledad/server/_incoming.py b/src/leap/soledad/server/_incoming.py index eded5932..1ccf74df 100644 --- a/src/leap/soledad/server/_incoming.py +++ b/src/leap/soledad/server/_incoming.py @@ -19,6 +19,7 @@ A twisted resource that saves externally delivered documents into user's db. """ import json import base64 +from twisted.logger import Logger from twisted.web.server import NOT_DONE_YET from twisted.web.resource import Resource from twisted.web.test.test_web import DummyRequest @@ -37,6 +38,9 @@ from leap.soledad.common.blobs import preamble __all__ = ['IncomingResource'] +logger = Logger() + + def _get_backend_from_config(): conf = get_config() if conf['blobs']: @@ -60,10 +64,14 @@ class IncomingResource(Resource): scheme = EncryptionSchemes.PUBKEY db = self.factory.open_database(uuid) if uses_legacy(db): - doc = ServerDocument(doc_id) - doc.content = self.formatter.format(request.content.read(), scheme) - db.put_doc(doc) - self._finish(request) + try: + doc = ServerDocument(doc_id) + content = request.content.read() + doc.content = self.formatter.format(content, scheme) + db.put_doc(doc) + self._finish(request) + except Exception as e: + self._error(e, request) else: raw_content = request.content.read() preamble = self.formatter.preamble(raw_content, doc_id) @@ -76,6 +84,7 @@ class IncomingResource(Resource): flagsReq.content = BytesIO(json.dumps([Flags.PENDING])) d.addCallback(lambda _: db.set_flags(uuid, doc_id, flagsReq, 'MX')) d.addCallback(lambda _: self._finish(request)) + d.addErrback(self._error, request) return NOT_DONE_YET def _finish(self, request): @@ -83,6 +92,7 @@ class IncomingResource(Resource): request.finish() def _error(self, e, request): + logger.error('Error processing request: %s' % e.getErrorMessage()) request.write('{"success": false}') request.setResponseCode(500) request.finish() |