Browse Source

Don't catch blanket Exception class

Instead of just catching the expected exceptions, catching all exceptions was
hiding the actual problem. A ValueError is thrown if you pass socket a string
instead of an int
Hamilton Turner 10 years ago
parent
commit
ec13e2a2d8
1 changed files with 3 additions and 2 deletions
  1. 3 2
      toolset/benchmark/benchmarker.py

+ 3 - 2
toolset/benchmark/benchmarker.py

@@ -715,13 +715,14 @@ class Benchmarker:
   # shutdown properly.
   ############################################################
   def __is_port_bound(self, port):
+    port = int(port)
     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     try:
       # Try to bind to all IP addresses, this port
       s.bind(("", port))
       # If we get here, we were able to bind successfully,
       # which means the port is free.
-    except Exception:
+    except socket.error:
       # If we get an exception, it might be because the port is still bound
       # which would be bad, or maybe it is a privileged port (<1024) and we
       # are not running as root, or maybe the server is gone, but sockets are
@@ -732,7 +733,7 @@ class Benchmarker:
         # If we get here, we were able to connect to something, which means
         # that the port is still bound.
         return True
-      except Exception:
+      except socket.error:
         # An exception means that we couldn't connect, so a server probably
         # isn't still running on the port.
         pass