From 32d576427179965def0a1757dc86a492e1c3756d Mon Sep 17 00:00:00 2001 From: Tim Pownall Date: Wed, 2 Mar 2016 14:38:24 -0600 Subject: [PATCH] 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 --- .../xenapi/etc/xapi.d/plugins/utils.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/utils.py b/plugins/xenserver/xenapi/etc/xapi.d/plugins/utils.py index 60d680ca9395..73ffa14cbec4 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/utils.py +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/utils.py @@ -460,7 +460,26 @@ def extract_tarball(fileobj, path, callback=None): callback(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: + LOG.exception("Failed while sending data to tar pid: %s" % tar_pid) try_kill_process(tar_proc) raise