Merge lp:~cjwatson/launchpadlib/timeout-eventually into lp:launchpadlib

Proposed by Colin Watson
Status: Merged
Merged at revision: 143
Proposed branch: lp:~cjwatson/launchpadlib/timeout-eventually
Merge into: lp:launchpadlib
Diff against target: 39 lines (+9/-0)
1 file modified
src/launchpadlib/credentials.py (+9/-0)
To merge this branch: bzr merge lp:~cjwatson/launchpadlib/timeout-eventually
Reviewer Review Type Date Requested Status
Dimitri John Ledkov Approve
Review via email: mp+264417@code.launchpad.net

Commit message

Time out make_end_user_authorize_token after 15 minutes.

Description of the change

Time out make_end_user_authorize_token after 15 minutes.

This should at least slightly mitigate issues with misconfigured server jobs that never give up.

To post a comment you must log in.
Revision history for this message
Dimitri John Ledkov (xnox) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/launchpadlib/credentials.py'
2--- src/launchpadlib/credentials.py 2014-11-08 12:26:25 +0000
3+++ src/launchpadlib/credentials.py 2015-07-10 13:38:50 +0000
4@@ -82,6 +82,7 @@
5 access_token_page = '+access-token'
6 authorize_token_page = '+authorize-token'
7 access_token_poll_time = 1
8+access_token_poll_timeout = 15 * 60
9
10 EXPLOSIVE_ERRORS = (MemoryError, KeyboardInterrupt, SystemExit)
11
12@@ -651,6 +652,7 @@
13 self.output(self.WAITING_FOR_LAUNCHPAD)
14 if browser is not None:
15 webbrowser.open(authorization_url)
16+ start_time = time.time()
17 while credentials.access_token is None:
18 time.sleep(access_token_poll_time)
19 try:
20@@ -669,6 +671,9 @@
21 # There was an error accessing the server.
22 print("Unexpected response from Launchpad:")
23 print(e)
24+ if time.time() >= start_time + access_token_poll_timeout:
25+ raise TokenAuthorizationTimedOut(
26+ "Timed out after %d seconds." % access_token_poll_timeout)
27
28
29 class TokenAuthorizationException(Exception):
30@@ -683,6 +688,10 @@
31 pass
32
33
34+class TokenAuthorizationTimedOut(TokenAuthorizationException):
35+ pass
36+
37+
38 class ClientError(TokenAuthorizationException):
39 pass
40

Subscribers

People subscribed via source and target branches