From 850a0e32f996cdcc6724e3900a40325aae719828 Mon Sep 17 00:00:00 2001 From: drebs Date: Tue, 10 Oct 2017 07:43:19 -0300 Subject: [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 --- src/leap/soledad/server/_incoming.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src') 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() -- cgit v1.2.3