From 6e114e44b543e29423f86408e5acdfbf7813c14e Mon Sep 17 00:00:00 2001 From: david-sarah Date: Sun, 23 May 2010 16:38:30 -0700 Subject: [PATCH] SFTP: avoid race condition where .write could be called on an OverwriteableFileConsumer after it had been closed. --- src/allmydata/frontends/sftpd.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/allmydata/frontends/sftpd.py b/src/allmydata/frontends/sftpd.py index d1265de6..819191a8 100644 --- a/src/allmydata/frontends/sftpd.py +++ b/src/allmydata/frontends/sftpd.py @@ -336,6 +336,7 @@ class OverwriteableFileConsumer(PrefixingLogMixin): self.downloaded = 0 self.milestones = [] # empty heap of (offset, d) self.overwrites = [] # empty heap of (start, end) + self.is_closed = False self.done = self.when_reached(download_size) # adds a milestone self.is_done = False def _signal_done(ign): @@ -376,6 +377,8 @@ class OverwriteableFileConsumer(PrefixingLogMixin): def write(self, data): if noisy: self.log(".write()" % (len(data),), level=NOISY) + if self.is_closed: + return if self.check_abort(): self.close() return @@ -520,6 +523,7 @@ class OverwriteableFileConsumer(PrefixingLogMixin): #self.unregisterProducer() def close(self): + self.is_closed = True self.finish() self.f.close() -- 2.45.2