Merge lp:~cjwatson/launchpad/more-robust-debdiff-timeout into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 19000
Proposed branch: lp:~cjwatson/launchpad/more-robust-debdiff-timeout
Merge into: lp:launchpad
Diff against target: 75 lines (+11/-10)
2 files modified
lib/lp/soyuz/model/packagediff.py (+7/-9)
lib/lp/soyuz/tests/test_packagediff.py (+4/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/more-robust-debdiff-timeout
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+369535@code.launchpad.net

Commit message

Use timeout(1) to limit debdiff rather than using alarm(3) ourselves.

Description of the change

The approach of calling alarm(3) and then execing the target command relies on the target command not changing the disposition of SIGALRM, and may have other problems (we've observed PackageDiffJobs occasionally hanging indefinitely, although we don't know exactly why that's happening). coreutils has a perfectly good timeout(1) program that we can use instead, which runs the target command as a child process and in general seems likely to be more robust.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/soyuz/model/packagediff.py'
2--- lib/lp/soyuz/model/packagediff.py 2015-12-02 10:57:23 +0000
3+++ lib/lp/soyuz/model/packagediff.py 2019-07-01 16:27:41 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009-2015 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2019 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 __metaclass__ = type
10@@ -13,7 +13,6 @@
11 import os
12 import resource
13 import shutil
14-import signal
15 import subprocess
16 import tempfile
17
18@@ -47,13 +46,11 @@
19 )
20
21
22-def limit_deb_diff(timeout, max_size):
23+def limit_deb_diff(max_size):
24 """Pre-exec function to apply resource limits to debdiff.
25
26- :param timeout: Time limit in seconds.
27 :param max_size: Maximum output file size in bytes.
28 """
29- signal.alarm(timeout)
30 _, hard_fsize = resource.getrlimit(resource.RLIMIT_FSIZE)
31 if hard_fsize != resource.RLIM_INFINITY and hard_fsize < max_size:
32 max_size = hard_fsize
33@@ -83,7 +80,10 @@
34 if name.lower().endswith('.dsc')]
35 [to_dsc] = [name for name in to_files
36 if name.lower().endswith('.dsc')]
37- args = ['debdiff', from_dsc, to_dsc]
38+ args = [
39+ 'timeout', str(config.packagediff.debdiff_timeout),
40+ 'debdiff', from_dsc, to_dsc,
41+ ]
42 env = os.environ.copy()
43 env['TMPDIR'] = tmp_dir
44
45@@ -94,9 +94,7 @@
46 process = subprocess.Popen(
47 args, stdout=out_file, stderr=subprocess.PIPE,
48 preexec_fn=partial(
49- limit_deb_diff,
50- config.packagediff.debdiff_timeout,
51- config.packagediff.debdiff_max_size),
52+ limit_deb_diff, config.packagediff.debdiff_max_size),
53 cwd=tmp_dir, env=env)
54 stdout, stderr = process.communicate()
55 finally:
56
57=== modified file 'lib/lp/soyuz/tests/test_packagediff.py'
58--- lib/lp/soyuz/tests/test_packagediff.py 2018-02-02 03:14:35 +0000
59+++ lib/lp/soyuz/tests/test_packagediff.py 2019-07-01 16:27:41 +0000
60@@ -1,4 +1,4 @@
61-# Copyright 2010-2018 Canonical Ltd. This software is licensed under the
62+# Copyright 2010-2019 Canonical Ltd. This software is licensed under the
63 # GNU Affero General Public License version 3 (see the file LICENSE).
64
65 """Test source package diffs."""
66@@ -173,6 +173,9 @@
67 with open(mock_debdiff_path, "w") as mock_debdiff:
68 print(dedent("""\
69 #! /bin/sh
70+ # Make sure we don't rely on the child leaving its SIGALRM
71+ # disposition undisturbed.
72+ trap '' ALRM
73 (echo "$$"; echo "$TMPDIR") >%s
74 sleep 5
75 """ % marker_path), end="", file=mock_debdiff)