Changeset - bcd18ce5de66
[Not reviewed]
default
0 1 0
Mads Kiilerich (mads) - 5 years ago 2020-12-20 22:43:30
mads@kiilerich.com
vcs: fix subprocessio process termination

659ecd26002c had a cut'n'paste error so it dropped process termination in the
SubprocessIOChunker close method.
1 file changed with 1 insertions and 1 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/vcs/subprocessio.py
Show inline comments
 
@@ -347,63 +347,63 @@ class SubprocessIOChunker(object):
 
        # Either way, if error (returned by ended process, or implied based on
 
        # presence of stuff in stderr output) we error out.
 
        # Else, we are happy.
 
        returncode = _p.poll()
 
        if (returncode is not None # process has terminated
 
            and returncode != 0
 
        ): # and it failed
 
            bg_out.stop()
 
            out = b''.join(bg_out)
 
            bg_err.stop()
 
            err = b''.join(bg_err)
 
            if (err.strip() == b'fatal: The remote end hung up unexpectedly' and
 
                out.startswith(b'0034shallow ')
 
            ):
 
                # hack inspired by https://github.com/schacon/grack/pull/7
 
                bg_out = iter([out])
 
                _p = None
 
            elif err:
 
                raise EnvironmentError("Subprocess exited due to an error: %s" % err)
 
            else:
 
                raise EnvironmentError(
 
                    "Subprocess exited with non 0 ret code: %s" % returncode)
 
        self.process = _p
 
        self.output = bg_out
 
        self.error = bg_err
 
        self.inputstream = inputstream
 

	
 
    def __iter__(self):
 
        return self
 

	
 
    def __next__(self):
 
        if self.process:
 
            returncode = self.process.poll()
 
            if (returncode is not None # process has terminated
 
                and returncode != 0
 
            ): # and it failed
 
                getattr(self.output, 'stop', lambda: None)()
 
                self.error.stop()
 
                err = ''.join(self.error)
 
                raise EnvironmentError("Subprocess exited due to an error:\n" + err)
 
        return next(self.output)
 

	
 
    def throw(self, type, value=None, traceback=None):
 
        if getattr(self.output, 'length') or not getattr(self.output, 'done_reading'):
 
            raise type(value)
 

	
 
    def close(self):
 
        try:
 
            getattr(self.output, 'terminate', lambda: None)()
 
            getattr(self.process, 'terminate', lambda: None)()
 
        except:
 
            pass
 
        try:
 
            getattr(self.output, 'close', lambda: None)()
 
        except:
 
            pass
 
        try:
 
            self.error.close()
 
        except:
 
            pass
 
        try:
 
            os.close(self.inputstream)
 
        except:
 
            pass
0 comments (0 inline, 0 general)