# HG changeset patch # User Marcin Kuzminski # Date 2019-01-16 13:18:10 # Node ID 560860c27980b05475c668832c3befbd8aeeb78c # Parent 0f0a8ed38acf36c75adc6a1ae14660d73f27d565 subprocession: limit fd leaks diff --git a/vcsserver/subprocessio.py b/vcsserver/subprocessio.py --- a/vcsserver/subprocessio.py +++ b/vcsserver/subprocessio.py @@ -66,15 +66,17 @@ class StreamFeeder(Thread): def run(self): t = self.writeiface - if self.bytes: - os.write(t, self.bytes) - else: - s = self.source - b = s.read(4096) - while b: - os.write(t, b) + try: + if self.bytes: + os.write(t, self.bytes) + else: + s = self.source b = s.read(4096) - os.close(t) + while b: + os.write(t, b) + b = s.read(4096) + finally: + os.close(t) @property def output(self): @@ -436,6 +438,7 @@ class SubprocessIOChunker(object): self.process = _p self.output = bg_out self.error = bg_err + self.inputstream = inputstream def __iter__(self): return self @@ -484,6 +487,10 @@ class SubprocessIOChunker(object): self.error.close() except: pass + try: + os.close(self.inputstream) + except: + pass def __del__(self): self.close()