Merge lp:~roadmr/checkbox/827859 into lp:checkbox

Proposed by Daniel Manrique
Status: Merged
Approved by: Brendan Donegan
Approved revision: 1013
Merged at revision: 1038
Proposed branch: lp:~roadmr/checkbox/827859
Merge into: lp:checkbox
Diff against target: 40 lines (+12/-0)
2 files modified
checkbox/job.py (+9/-0)
debian/changelog (+3/-0)
To merge this branch: bzr merge lp:~roadmr/checkbox/827859
Reviewer Review Type Date Requested Status
Brendan Donegan (community) Approve
Daniel Manrique (community) Needs Resubmitting
Review via email: mp+72786@code.launchpad.net

Description of the change

This code guards against the situation encountered in bug 827859, where a bogus timeout value can cause the backend to crash. I suspect it may have been caused by the user creating a job with a strange timeout value, but it's good to handle this in the code I think.

I'm turning all strange timeout values to zero, which in practice causes jobs with bad timeouts to outright exit as they don't complete "before" the timeout, but I think this is more desirable than a crashing backend. A possible refinement would be a default (a few seconds) timeout, but I'm not sure it's worth it on safety-net code like this.

Also if you can think of a better way to handle this (this is a bit verbose at 8 lines of code) it would be nice :)

To post a comment you must log in.
Revision history for this message
Brendan Donegan (brendan-donegan) wrote :

In my opinion it might be better to default to something sensible rather than 0 for the timeout (30 seconds?), I haven't seen an example of a bogus timeout so I'm assuming the would fall under the category of 'programming error'?

Also, I don't think it's really worth changing the code for (as it reads just fine), but this would be shorter (only barely!):

if timeout is not None:
    try:
        timeout = float(timeout)
        if timeout < 0: timeout = 0
    except:
        timeout = 0 # This could maybe be 30 as a sensible default

review: Needs Information
lp:~roadmr/checkbox/827859 updated
1012. By Daniel Manrique

merged from trunk

1013. By Daniel Manrique

use a default timeout instead of 0 when a job specifies invalid timeout

Revision history for this message
Daniel Manrique (roadmr) wrote :

Thanks, I was also unsure about the 0 seconds thing, I added a default timeout of 30 seconds.

Turns out the bogus timeout stems from bug 833747 which results in invalid job descriptions, potentially also if a user uses a timeout: value of negative or a string (timeout: forever). Still I think this bit of code is worth having.

review: Needs Resubmitting
Revision history for this message
Brendan Donegan (brendan-donegan) wrote :

Approved.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'checkbox/job.py'
2--- checkbox/job.py 2010-04-20 16:23:16 +0000
3+++ checkbox/job.py 2011-09-09 14:47:31 +0000
4@@ -37,6 +37,7 @@
5
6 ALL_STATUS = [FAIL, PASS, UNINITIATED, UNRESOLVED, UNSUPPORTED, UNTESTED]
7
8+DEFAULT_JOB_TIMEOUT = 30 #used in case a job specifies invalid timeout
9
10 class Job(object):
11
12@@ -47,6 +48,14 @@
13 self.command = command
14 self.environ = environ
15 self.timeout = timeout
16+ if self.timeout is not None:
17+ try:
18+ self.timeout = float(self.timeout)
19+ except:
20+ self.timeout =DEFAULT_JOB_TIMEOUT
21+ finally:
22+ if self.timeout < 0:
23+ self.timeout = DEFAULT_JOB_TIMEOUT
24
25 def execute(self):
26 # Sanitize environment
27
28=== modified file 'debian/changelog'
29--- debian/changelog 2011-09-09 13:43:17 +0000
30+++ debian/changelog 2011-09-09 14:47:31 +0000
31@@ -11,6 +11,9 @@
32 * Several corrections necessary due to test name changes or typos found in
33 job files
34
35+ [Daniel Manrique]
36+ * checkbox/job.py: Guard against bogus timeout values (LP: #827859)
37+
38 -- Daniel Manrique <daniel.manrique@canonical.com> Thu, 08 Sep 2011 14:53:55 -0400
39
40 checkbox (0.12.6) oneiric; urgency=low

Subscribers

People subscribed via source and target branches