From 3180d0544afc8000c06065c223d5cf104e806275 Mon Sep 17 00:00:00 2001 From: drebs Date: Tue, 18 Aug 2015 12:16:47 -0300 Subject: [bug] hold sync lock while running post-sync hooks Previous to this modification, the post-sync hooks were run after the sync lock was released. In that scenario, the next sync process could start before the previous sync's post-sync hooks were run. In general, we want the hooks to run while the current sync lock is still locked, even though for some plugins this might not make a difference. --- client/src/leap/soledad/client/api.py | 36 +++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'client') diff --git a/client/src/leap/soledad/client/api.py b/client/src/leap/soledad/client/api.py index 6fcc8d79..b91e497f 100644 --- a/client/src/leap/soledad/client/api.py +++ b/client/src/leap/soledad/client/api.py @@ -656,31 +656,39 @@ class Soledad(object): """ Synchronize documents with the server replica. + This method uses a lock to prevent multiple concurrent sync processes + over the same local db file. + :param defer_decryption: Whether to defer decryption of documents, or do it inline while syncing. :type defer_decryption: bool - :return: A deferred whose callback will be invoked with the local - generation before the synchronization was performed. + :return: A deferred lock that will run the actual sync process when + the lock is acquired, and which will fire with with the local + generation before the synchronization was performed. :rtype: twisted.internet.defer.Deferred """ + d = self.sync_lock.run( + self._sync, + defer_decryption) + return d - # ----------------------------------------------------------------- - # TODO this needs work. - # Should review/write tests to check that this: - - # (1) Defer to the syncer pool -- DONE (on dbsyncer) - # (2) Return the deferred - # (3) Add the callback for signaling the event (executed on reactor - # thread) - # (4) Check that the deferred is called with the local gen. + def _sync(self, defer_decryption): + """ + Synchronize documents with the server replica. - # ----------------------------------------------------------------- + :param defer_decryption: + Whether to defer decryption of documents, or do it inline while + syncing. + :type defer_decryption: bool + :return: A deferred whose callback will be invoked with the local + generation before the synchronization was performed. + :rtype: twisted.internet.defer.Deferred + """ sync_url = urlparse.urljoin(self._server_url, 'user-%s' % self.uuid) - d = self.sync_lock.run( - self._dbsyncer.sync, + d = self._dbsyncer.sync( sync_url, creds=self._creds, defer_decryption=defer_decryption) -- cgit v1.2.3