xenapi: fix when tar exits early during download

When downloading a streamed chunk from swift through glance gives tar
invalid input, tar will exit, but leave the plugin still trying to write
data to the dead process.

To stop this we can spot when the tar process exits early, and be sure
to stop trying to write more data to the dead process.

Change-Id: Ic2bc89fa6d08db505b044a9498c1bfa5b884a056
Closes-Bug: 1552293
This commit is contained in:
Tim Pownall 2016-03-02 14:38:24 -06:00 committed by Tim Pownall
parent abc0f8fce2
commit 32d5764271

View File

@ -460,7 +460,26 @@ def extract_tarball(fileobj, path, callback=None):
callback(chunk) callback(chunk)
tar_proc.stdin.write(chunk) tar_proc.stdin.write(chunk)
# NOTE(tpownall): If we do not poll for the tar process exit
# code when tar has exited pre maturely there is the chance
# that tar will become a defunct zombie child under glance plugin
# and re parented under init forever waiting on the stdin pipe to
# close. Polling for the exit code allows us to break the pipe.
returncode = tar_proc.poll()
tar_pid = tar_proc.pid
if returncode is not None:
LOG.error("tar extract with process id '%(pid)s' "
"exited early with '%(rc)s'" %
{'pid': tar_pid, 'rc': returncode})
raise SubprocessException(
' '.join(tar_cmd), returncode, "", "")
except SubprocessException:
# no need to kill already dead process
raise
except Exception: except Exception:
LOG.exception("Failed while sending data to tar pid: %s" % tar_pid)
try_kill_process(tar_proc) try_kill_process(tar_proc)
raise raise