]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Fix race condition in upload deque
authorDavid Stainton <dstainton415@gmail.com>
Tue, 21 Apr 2015 04:48:16 +0000 (05:48 +0100)
committerDavid Stainton <dstainton415@gmail.com>
Tue, 21 Apr 2015 04:48:16 +0000 (05:48 +0100)
src/allmydata/frontends/drop_upload.py

index 2e494ab4b088825f13448441493e8444d2a0b838..d6e9e60876bcc61b5cd69c74b6f969d2838a57f0 100644 (file)
@@ -40,6 +40,7 @@ class DropUploader(service.MultiService):
 
         self._objid = None
         self._classname = 'DropUploader'
+        self._upload_lazy_tail = None
         self._pending = set()
         self._client = client
         self._stats_provider = client.stats_provider
@@ -158,7 +159,6 @@ class DropUploader(service.MultiService):
         self._turn_deque()
 
     def _append_to_deque(self, path):
-        print "_append_to_deque"
         self._upload_deque.append(path)
         self._pending.add(path)
         self._stats_provider.count('drop_upload.objects_queued', 1)
@@ -170,9 +170,13 @@ class DropUploader(service.MultiService):
             path = self._upload_deque.pop()
         except IndexError:
             self._log("magic folder upload deque is now empty")
+            self._upload_lazy_tail = None
             return
-        d = task.deferLater(reactor, 0, self._process, path)
-        d.addCallback(lambda ign: self._turn_deque())
+        if self._upload_lazy_tail is not None:
+            self._upload_lazy_tail.addCallback(lambda ign: task.deferLater(reactor, 0, self._process, path))
+        else:
+            self._upload_lazy_tail = task.deferLater(reactor, 0, self._process, path)
+        self._upload_lazy_tail.addCallback(lambda ign: self._turn_deque())
 
     def _notify(self, opaque, path, events_mask):
         self._log("inotify event %r, %r, %r\n" % (opaque, path, ', '.join(self._inotify.humanReadableMask(events_mask))))