From 7a9f52d2e5b41645dde41333ff5fe31e403d23ec Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Wed, 20 Feb 2019 12:41:33 -0500 Subject: [PATCH] make sure shutdown failures go somewhere good --- src/allmydata/frontends/magic_folder.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/allmydata/frontends/magic_folder.py b/src/allmydata/frontends/magic_folder.py index a8b5be32b..780759d0f 100644 --- a/src/allmydata/frontends/magic_folder.py +++ b/src/allmydata/frontends/magic_folder.py @@ -22,6 +22,7 @@ from eliot import ( Field, ActionType, MessageType, + write_failure, ) from eliot.twisted import DeferredContext @@ -406,14 +407,11 @@ class MagicFolder(service.MultiService): def stopService(self): with MAGIC_FOLDER_STOP(nickname=self.name).context(): - d = DeferredContext(defer.gatherResults([ - self.uploader.stop(), - self.downloader.stop(), - ])) - d.addBoth( - lambda ign: service.MultiService.stopService(self) - ) - return d.addActionFinish() + d = DeferredContext(self._finish()) + d.addBoth( + lambda ign: service.MultiService.stopService(self) + ) + return d.addActionFinish() def ready(self): """ready is used to signal us to start @@ -422,6 +420,14 @@ class MagicFolder(service.MultiService): self.uploader.start_uploading() # synchronous, returns None return self.downloader.start_downloading() + def _finish(self): + d0 = self.downloader.stop() + d1 = self.uploader.stop() + return defer.DeferredList([ + DeferredContext(d0).addErrback(write_failure).result, + DeferredContext(d1).addErrback(write_failure).result, + ]) + _NICKNAME = Field.for_types( u"nickname",