Bug 892948 - Add timeouts to urllib2.urlopen() calls; r=sfink
authorEd Morley <emorley@mozilla.com>
Fri, 12 Jul 2013 14:40:32 +0100
changeset 118 ac634b806473
parent 117 e90b3081344d
child 119 f2ab71eb6995
push id53
push useremorley@mozilla.com
push date2013-07-12 13:41 +0000
reviewerssfink
bugs892948
Bug 892948 - Add timeouts to urllib2.urlopen() calls; r=sfink
__init__.py
bzauth.py
--- a/__init__.py
+++ b/__init__.py
@@ -312,17 +312,17 @@ def bugzilla_info(ui, profile):
     auth = bzauth.get_auth(ui, bugzilla, profile, username, password)
     return (auth, api_server, bugzilla)
 
 def urlopen(ui, req):
     """Wraps urllib2.urlopen() to provide error handling."""
     ui.progress('Accessing bugzilla server', None, item=req.get_full_url())
     #ui.debug("%s %s\n" % (req.get_method(), req.get_data()))
     try:
-        return urllib2.urlopen(req)
+        return urllib2.urlopen(req, timeout=30)
     except urllib2.HTTPError, e:
         msg = ''
         try:
             err = json.load(e)
             msg = err['message']
         except:
             msg = e
             pass
--- a/bzauth.py
+++ b/bzauth.py
@@ -130,17 +130,17 @@ def load_configuration(ui, api_server, f
     except:
         global_cache[api_server] = cache
     now = time.time()
     if cache.get('configuration', None) and now - cache['configuration_timestamp'] < 24*60*60*7:
         return cache['configuration']
 
     ui.write("Refreshing configuration cache for " + api_server + "\n")
     try:
-        cache['configuration'] = json.load(urllib2.urlopen(bz.get_configuration(api_server)))
+        cache['configuration'] = json.load(urllib2.urlopen(bz.get_configuration(api_server), timeout=30))
     except Exception, e:
         raise util.Abort("Error loading bugzilla configuration: " + str(e))
 
     cache['configuration_timestamp'] = now
     store_global_cache(filename)
     return cache['configuration']
 
 def win_get_folder_path(folder):
@@ -293,17 +293,17 @@ def get_auth(ui, bugzilla, profile, user
     if not password:
         password = ui.getpass("Enter password for %s: " % username)
 
     return bzAuth(username=username, password=password)
 
 def get_username(api_server, token):
     req = bz.get_user(api_server, token)
     try:
-        user = json.load(urllib2.urlopen(req))
+        user = json.load(urllib2.urlopen(req, timeout=30))
         return user["name"]
     except urllib2.HTTPError, e:
         msg = ''
         try:
             err = json.load(e)
             msg = err['message']
         except:
             msg = e