add 5 minute timeout on binary patch construction
When making bsdiff/imgdiff patches, give up after 5 minutes. (On
certain large files it can take hours to build a patch, if it ever
even completes.)
Change-Id: I123c06f8194f85f6f4e640f7eb31c7746f76ba4d
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index 15964b1..50ef451 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -900,10 +900,26 @@
cmd.append(ttemp.name)
cmd.append(ptemp.name)
p = Run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- _, err = p.communicate()
+ err = []
+ def run():
+ _, e = p.communicate()
+ if e: err.append(e)
+ th = threading.Thread(target=run)
+ th.start()
+ th.join(timeout=300) # 5 mins
+ if th.is_alive():
+ print "WARNING: diff command timed out"
+ p.terminate()
+ th.join(5)
+ if th.is_alive():
+ p.kill()
+ th.join()
+
if err or p.returncode != 0:
- print "WARNING: failure running %s:\n%s\n" % (diff_program, err)
- return None
+ print "WARNING: failure running %s:\n%s\n" % (
+ diff_program, "".join(err))
+ self.patch = None
+ return None, None, None
diff = ptemp.read()
finally:
ptemp.close()