Эх сурвалжийг харах

HUE-8737 [py3] Avoid unbound exception on Thrift connection error

Now the e object is not present anymore.
UnboundLocalError: local variable 'e' referenced before assignment
Romain 6 жил өмнө
parent
commit
31aab53ba9

+ 1 - 1
apps/security/src/security/templates/layout.mako

@@ -54,7 +54,7 @@ def is_selected(section, matcher):
           <div class="nav-collapse">
             <ul class="nav">
               <li class="app-header">
-                <a href="/${app_name}">
+                <a href="/security">
                   <i class="fa fa-lock"></i>
                   ${ _('Security Browser') if is_embeddable else _('Hadoop Security') }
                 </a>

+ 18 - 16
desktop/core/src/desktop/lib/thrift_util.py

@@ -498,29 +498,31 @@ class SuperClient(object):
           duration = time.time() - st
 
           # Log the duration at different levels, depending on how long it took.
-          logmsg = "Thrift call: %s.%s(args=%s, kwargs=%s) returned in %dms: %s" % (str(self.wrapped.__class__), attr, str_args, repr(kwargs), duration * 1000, log_msg)
+          logmsg = "Thrift call: %s.%s(args=%s, kwargs=%s) returned in %dms: %s" % (
+            str(self.wrapped.__class__),
+            attr, str_args, repr(kwargs), duration * 1000, log_msg
+          )
           log_if_slow_call(duration=duration, message=logmsg)
 
           return ret
-        except socket.error as e:
-          pass
-        except TTransportException as e:
-          pass
+        except (socket.error, socket.timeout, TTransportException) as e:
+          self.transport.close()
+
+          if isinstance(e, socket.timeout) or 'read operation timed out' in str(e): # Can come from ssl.SSLError
+            logging.warn("Not retrying thrift call %s due to socket timeout" % attr)
+            raise
+          else:
+            tries_left -= 1
+            if tries_left:
+              logging.info("Thrift exception; retrying: " + str(e), exc_info=0)
+              if 'generic failure: Unable to find a callback: 32775' in str(e):
+                logging.warn("Increase the sasl_max_buffer value in hue.ini")
+            else:
+              raise
         except Exception as e:
           logging.exception("Thrift saw exception (this may be expected).")
           raise
 
-        self.transport.close()
-
-        if isinstance(e, socket.timeout) or 'read operation timed out' in str(e): # Can come from ssl.SSLError
-          logging.warn("Not retrying thrift call %s due to socket timeout" % attr)
-          raise
-        else:
-          tries_left -= 1
-          if tries_left:
-            logging.info("Thrift exception; retrying: " + str(e), exc_info=0)
-            if 'generic failure: Unable to find a callback: 32775' in str(e):
-              logging.warn("Increase the sasl_max_buffer value in hue.ini")
       logging.warn("Out of retries for thrift call: " + attr)
       raise
     return wrapper

+ 1 - 1
desktop/libs/libsentry/src/libsentry/sentry_site.py

@@ -175,7 +175,7 @@ def _parse_sites():
 
 def _parse_site(site_path):
   try:
-    data = file(site_path, 'r').read()
+    data = open(site_path, 'r').read()
   except IOError as err:
     if err.errno != errno.ENOENT:
       LOG.error('Cannot read from "%s": %s' % (site_path, err))